C语言更改文件名(原创)

您所在的位置:网站首页 c语言怎么改文件名称和内容 C语言更改文件名(原创)

C语言更改文件名(原创)

2023-05-17 19:04| 来源: 网络整理| 查看: 265

#include #include

int main(int argv, char *argc) {     long handle;     int i=0, j=0;     struct _finddata_t fileinfo;      char filePT[256]={'\0'};      char fileType[20]={'a','\0'};     char filePath[256]={'\0'};     char newName[256]={'\0'};     char oldName[256]={'\0'};           printf("Input the rename filePath:\n");      scanf("%s", filePath);     fflush(stdin);     printf("Input the rename fileType:\n");     scanf("%s", fileType);     fflush(stdin);

    sprintf(filePT, "%s\\*%s",filePath, fileType);          handle = _findfirst(filePT, &fileinfo);     if(-1 == handle)     {         printf("_findfirst() error\n");         getchar();         return(-1);     }     i=1000;     do{         sprintf(oldName, "%s\\%s", filePath, fileinfo.name);//全部路径         sprintf(newName, "%s\\%d%s", filePath, i++, fileType);         j=rename(oldName, newName);         if(j != 0)         {              printf("rename() error\n");              break;         }     }while( !_findnext(handle, &fileinfo) );

    _findclose(handle);     printf("Program End\n");     getchar();     return(0); }



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3