void ChangeName(string filename)
{
char flagcharacter = 'a'; // 要在文件名前添加的标志字符
int filelocation = 0 ; // 暂存文件名起始下标
int directoryend = 0 ; // 暂存文件夹名结束下标
for(int i = (filename.length() - 1); i>=0; i--)
if(filename[i] == '/' || filename[i] == '\\')
{
directoryend = i ;
filelocation = i+1 ;
break;
}
char oldfile[500], newfile[500] ;
memset(oldfile, '\0', 500) ;
memset(newfile, '\0', 500) ;
for(int i=0; i<filename.length(); i++)
oldfile[i] = filename[i] ;
for(int i=0; i<=directoryend; i++)
{
newfile[i] = filename[i];
}
newfile[directoryend+1] = flagcharacter;
for(int i=filelocation; i<filename.length(); i++)
newfile[i+1] = filename[i] ;
rename(oldfile, newfile);
}
此函数参考了来自C语言的rename function in C