根據文件夾名命名文件夾裏的文件

軟件界面:

核心代碼:

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;
}

 

發佈了61 篇原創文章 · 獲贊 11 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章