軟件界面:
核心代碼:
int RenameOneFile(const _tstring& stCurFile, const _tstring& stDstDir)
{
_tstring stDirName = CStdStr::GetNameOfDir(CStdStr::GetDirOfFile(stCurFile));
const std::string sCurItem = CStdStr::ws2s(stCurFile);
_tstring stDstPath = stDstDir + stDirName + CStdStr::GetSuffixOfFile(stCurFile);
//如果文件已經存在
int nNameIndex = 0;
while(CStdFile::IfAccessFile(stDstPath))
{
stDstPath = stDstDir + stDirName + ToString(nNameIndex++) + CStdStr::GetSuffixOfFile(stCurFile);
}
const std::string sDstPath = CStdStr::ws2s(stDstPath);
if (rename(sCurItem.c_str(), sDstPath.c_str()) == 0)
{
CLOG::Out(_T("%s -> %s"), sCurItem.c_str(), sDstPath.c_str());
}
return 0;
}