C语言更改文件名(原创) | 您所在的位置:网站首页 › c语言怎么改文件名称和名称 › C语言更改文件名(原创) |
#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 实验室设备网 版权所有 |