
原來的檔案命名是“1”“2”“3”,直接按數字排序的bmp格式圖片,
現在想要換成“日期+五位數編號”,就是比如“2018051610001”“2018051610002”這樣的,然后按后五位數排序寫入m_vStrAllFiles陣列,這個應該怎么修改代碼,求大佬幫忙
代碼貼出來:
CFileFind find;
CString strTemp = strPath;
int npos1=FistImageFilename.ReverseFind('\\');
int npos2=FistImageFilename.Find(_T(".bmp"));
CString FirstImageNum=FistImageFilename.Mid(npos1+1,npos2-npos1-1);
/*CString strDirectory= strPath + _T("\\") + _T("\\499.bmp");*/
CString strDirectory;
CString strFile=FirstImageNum+_T(".bmp");
CString ImageNum;
int num=_ttoi(FirstImageNum);
BOOL IsFind = TRUE;
while(IsFind)
{
num=num+1;
m_vStrAllFiles.push_back(strFile);
ImageNum.Format(_T("%d"),num);
strFile=ImageNum+_T(".bmp");
strDirectory=strPath+_T("\\\\")+strFile;
IsFind = find.FindFile(strDirectory);
}
find.Close();
uj5u.com熱心網友回復:
WIN32_FIND_DATA FindFileData;FILETIME ft=FindFileData.ftCreationTime;
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft);
FileTimeToSystemTime(&ft,&st);
sprintf(buf,_T("%4d年%02d月%02d日%02d:%02d:%02d"),
st.wYear,st.wMonth,st.wDay,st.wHour/*北京時間*/,st.wMinute,st.wSecond);
string strFilePath=lpPath;
uj5u.com熱心網友回復:
函式 如下:
void find(LPCTSTR lpPath,vector<FileInfo>& FileList)
{
string szFind(lpPath);
WIN32_FIND_DATA FindFileData;
szFind+=_T("\\*.*");
HANDLE hFind=::FindFirstFile(szFind.c_str(),&FindFileData);
if(INVALID_HANDLE_VALUE=https://bbs.csdn.net/topics/=hFind) return;
//
do
{
if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{// dir
if(FindFileData.cFileName[0] != '.')
{
string szPath(lpPath);
szPath+=_T("\\");
szPath+=FindFileData.cFileName;
//TRACE1("%s\n",szPath.c_str());
find(szPath.c_str(),FileList);
}
}
else
{// file
string strFileName=FindFileData.cFileName;//檔案名
//TRACE1("%s\n",strFileName.c_str());
int at = strFileName.find_last_of('.');
if(at<0) continue;// file without extention
string ext=strFileName.substr(at);
//TRACE1("%s\n",ext.c_str());
//
at=0;// reset
while(((int)at=suffixStr.find(ext,at))>=0)// find type
// if(stricmp(suffixStr.c_str(),_T(".txt"))==0)
{// not suffixStr.c_str()==_T(".txt") ; never == !
//afxDump << at << "\n";
at+=ext.size();// move to seperetor '.'
if(suffixStr[at] != '.') continue;// not wanted !
//
FILETIME ft=FindFileData.ftCreationTime;
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft);
FileTimeToSystemTime(&ft,&st);
sprintf(buf,_T("%4d年%02d月%02d日%02d:%02d:%02d"),
st.wYear,st.wMonth,st.wDay,st.wHour/*北京時間*/,st.wMinute,st.wSecond);
string strFilePath=lpPath;
FileInfo fi;
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
//TRACE1("%s\n",strFileName.c_str());
FileList.push_back(fi);
}
}
} while (::FindNextFile (hFind, &FindFileData));
}
uj5u.com熱心網友回復:
system("dir /b /a-d c:\\*.* >d:\\allfiles.txt");//讀檔案d:\\allfiles.txt的內容即C:\\下所有檔案的名字
system("dir /b /a-d /s c:\\*.* >d:\\allfilesinsub.txt");
//讀檔案d:\\allfilesinsub.txt的內容即C:\\下所有檔案的名字包含子目錄
system("dir /b /ad c:\\*.* >d:\\alldirs.txt");
//讀檔案d:\\alldirs.txt的內容即C:\\下所有子目錄的名字
請記住,能用shell命令獲取檔案、檔案夾資訊或者操作檔案、檔案夾最好用shell命令獲取或者操作,而不要用各種API獲取或者操作,因為當遇到非法檔案夾名或非法檔案名或非法檔案長度、非法檔案日期、壓縮檔案、鏈接檔案、稀疏檔案……等各種意料之外的情況時,API會處理的不全面或陷入死回圈,而shell命令不會。
如果嫌system黑視窗一閃,將system("...")替換為WinExec("cmd /c ...",SW_HIDE);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/70001.html
標籤:基礎類
