64,662
社区成员
发帖
与我相关
我的任务
分享
long hFile;
char oldname[_MAX_PATH];
const char *newname = NULL;
_finddata_t fileinfo;
if( (hFile=_findfirst("*.*", &fileinfo))!=-1 ){
do{
if(!(fileinfo.attrib & _A_SUBDIR)){
oldname = fileinfo.name;
string str = fileinfo.name;
string::size_type spos = str.find("[", 0);
string::size_type epos = str.find("]", 0);
if(!(spos==string::npos) && !(epos==string::npos) ){
str.replace(spos, epos-spos+1, "");
newname = str.c_str();
if(rename(oldname, newname)!=0) {
cout<<"rename "<<oldname<<" to "<<newname<<" failed!"<<endl;
cout<<errno<<endl;
};
}
}
}while(_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
@for /L %I in (1,1,5) do @echo "" > [www.mywebsite.com]文件名_%I.txt
@dir
@echo renaming ...
@for /L %I in (1,1,5) do @echo @ren [www.mywebsite.com]文件名_%I.txt 文件名_%I.txt >> rename.bat
rename.bat
@del /Q rename.bat
@dir
oldname = fileinfo.name;这段代码不会报错???