Home > Software engineering >  MFC traverse the file name written array
MFC traverse the file name written array

Time:09-23


The original file name is "1" "2" "3", direct digital by the BMP format pictures,
Now want to switch to "date + 5 digit number," is like "2018051610001" "2018051610002", and then sort by five digits after written m_vStrAllFiles arrays, this should be how to modify the code, bosses help

Post code:
CFileFind find;
Cstrings strTemp=strPath;
Int npos1=FistImageFilename. ReverseFind (' \ \ ');
Int npos2=FistImageFilename. Find (_T (". BMP "));
Cstrings FirstImageNum=FistImageFilename. Mid (npos1 + 1, npos2 npos1-1);
/* cstrings strDirectory=strPath + _T (" \ \ ") + _T (" \ \ 499. BMP "); */

Cstrings strDirectory;
Cstrings strFile=FirstImageNum + _T (". BMP ");
Cstrings ImageNum;
Int num=_ttoi (FirstImageNum);
BOOL IsFind=TRUE;
While (IsFind)
{
num=num+1;
M_vStrAllFiles. Push_back (strFile);
ImageNum. The Format (_T (" % d "), num);
StrFile=ImageNum + _T (". BMP ");
StrDirectory=strPath + _T (" \ \ \ \ ") + strFile;
IsFind=find. FindFile (strDirectory);

}
The find. The Close ();

CodePudding user response:

WIN32_FIND_DATA FindFileData;


FILETIME ft=FindFileData. FtCreationTime;
SYSTEMTIME st={0};
TCHAR buf [64]={0};
FileTimeToLocalFileTime (& amp; (FindFileData. FtCreationTime), & amp; Ft);
FileTimeToSystemTime (& amp; The ft, & amp; St);
Sprintf (buf, _T (" % % 4 d years 02 02 on 02 d % d % d: % 02 d: % 2 d "),
St. wYear, st. wMonth, st. wDay, st. wHour/* */Beijing time, st. wMinute, st. wSecond);
String strFilePath=lpPath;

CodePudding user response:

Function is as follows:
 
Void the find (LPCTSTR lpPath vector & FileList)
{
String szFind (lpPath);
WIN32_FIND_DATA FindFileData;
SzFind +=_T (" \ \ *. * ");
HANDLE hFind=: : FindFirstFile (szFind c_str (), & amp; FindFileData);
If (INVALID_HANDLE_VALUE=https://bbs.csdn.net/topics/=hFind) return;
//
Do
{
If (FindFileData dwFileAttributes & amp; 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 (), the FileList);
}
}
The else
{//file
String strFileName=FindFileData. CFileName;//file name
//TRACE1 (" % s \ n ", strFileName c_str ());
Int the at=strFileName. Find_last_of (');
If (at<0) continue;//file without extention
String ext.=strFileName substr (at);
//TRACE1 (" % s \ n ", ext c_str ());
//
The at=0;//reset
While (((int) at=suffixStr. Find (ext, ats)) & gt;=0)//find the type
//if (stricmp (suffixStr c_str (), _T (". TXT "))==0)
{//not suffixStr. C_str ()==_T (". TXT "); Never==!
//afxDump & lt; The at +=ext size ();//move to seperetor '
If (suffixStr [at]!=') continue;//not wanted!
//
FILETIME ft=FindFileData. FtCreationTime;
SYSTEMTIME st={0};
TCHAR buf [64]={0};
FileTimeToLocalFileTime (& amp; (FindFileData. FtCreationTime), & amp; Ft);
FileTimeToSystemTime (& amp; The ft, & amp; St);
Sprintf (buf, _T (" % % 4 d years 02 02 on 02 d % d % d: % 02 d: % 2 d "),
St. wYear, st. wMonth, st. wDay, st. wHour/* */Beijing time, st. wMinute, st. wSecond);
String strFilePath=lpPath;
The FileInfo fi;
Fi. SzFileName=strFileName;
Fi. SzFilePath=strFilePath;
Fi. SzCreateTime=buf;
//TRACE1 (" % s \ n ", strFileName c_str ());
FileList. Push_back (fi);
}
}
} while (: : FindNextFile (hFind, & amp; FindFileData));
}

CodePudding user response:

System (" dir/b/a - d c: \ \ *. * & gt; D: \ \ allfiles TXT ");
//read file d: \ \ allfiles TXT content of C: \ \ under the names of all files
System (" dir/b/a - d/s c: \ \ *. * & gt; D: \ \ allfilesinsub TXT ");
//read file d: \ \ allfilesinsub TXT content that is C: \ \ under the names of all files contain subdirectories
System (" dir/b/active directory c: \ \ *. * & gt; D: \ \ alldirs TXT ");
//read file d: \ \ alldirs TXT content of C: \ \ under the names of all the subdirectories
Please remember, can use the shell command to get the file and folder information or manipulate files, folders had better use the shell command to get or operation, and don't use all sorts of API access to or operation, because when it comes to illegal folder name or illegal filename or illegal file length, illegal file date, compressed file, link files, sparse file... All sorts of unexpected situations, such as API can deal with incomplete or into an infinite loop, and shell commands not,
If disrelish black window system that the system ("... ") is replaced by WinExec (" CMD/c... ", SW_HIDE);
  • Related