阿晨1998
1.用C语言自定义文件名,涉及到的相关知识如下:_finddata_t结构体:struct _finddata_t {unsigned attrib ; time_t time_create ; time_t time_access ; time_t time_write ; _fsize_t size ; char name [260] ;}rename函数:功能描述:改变文件的名称或者位置,如果目标已存在,将被自动覆盖。 用法:#include int rename(const char *oldpath, const char *newpath);参数: oldpath:旧文件名。newpath:新文件名或者新位置。 返回说明: 成功执行时,返回0。失败返回-1,errno被设为以下的某个值 EACCES:权能不足EBUSY:参数oldpath或者newpath代表的是目录,而且一些进程正在使用它们EFAULT: 内存空间不可访问EINVAL:参数无效EISDIR:newpath是一个现存的目录,而oldpath不是目录ELOOP :路径解析的过程中存在太多的符号连接EMLINK:目录超出允许的最大连接数ENAMETOOLONG:路径名超出可允许的长度ENOENT:路径名部分内容表示的目录不存在ENOMEM: 核心内存不足ENOSPC: 磁盘配额限制或空间不足ENOTDIR:路径名的部分内容不是目录EPERM : 包含路径名的文件系统不支持建立目录EROFS:文件系统只读ENOTEMPTY:newpath是一个非空的目录,除了. 和 ..以外,还包含其它入口。EEXIST:同上EXDEV:oldpath和newpath不处于同一文件系统2.用C语言自定义文件名的代码例程如下:1234567891011121314151617181920212223242526272829303132333435363738394041424344#include#includeint 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);}