bool MyRename(String SourceName,String ToName)
{
SourceName+=AnsiString((char)0x00);
ToName+=AnsiString((char)0x00);
TSHFileOpStruct F;
F.hwnd=0;
F.wFunc=FO_RENAME;
F.pFrom=SourceName.c_str();
F.pTo=ToName.c_str();
F.fFlags=FOF_NOERRORUI;
// F.fFlags=FOF_MULTIDESTFILES+FOF_CONFIRMMOUSE+FOF_SILENT+FOF_RENAMEONCOLLISION+FOF_NO_CONNECTED_ELEMENTS;
return(SHFileOperation(&F)==0);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TSearchRec sr;
int iAttributes = 0;
iAttributes = faDirectory ;
String Name;
if (FindFirst(Edit1->Text.Trim()+"//*.*", iAttributes, sr) == 0)
{
do
{
if ((sr.Attr & iAttributes) == sr.Attr)
{
Name=sr.Name;
if(Name.Length()>=12)
{
MyRename(Edit1->Text.Trim()+"//"+Name,Edit1->Text.Trim()+"//"+Name.SubString(3,Name.Length()-3));
RichEdit1->Lines->Add(Edit1->Text.Trim()+"//"+Name);
}
}
} while (FindNext(sr) == 0);
FindClose(sr);
}
}
有一些能換名有一些不行,但是如果目錄隻有一個就可以換名,批量換名不行啊