1
Use the DOS command to save all file names in the folder to the specified file, then read from the file and store in the vector
String imglist_file = "Test_result\\imglist.txt";//Store file name list
string temp_imgname;
String Dir_command ("dir");
Dir_command + = M_strimageset + "/b >" + imglist_file;//m_strimageset is the variable that I built before I stored the folder path
ifstream file (imglist_ File.c_str (), ios::in);
System (DIR_COMMAND.C_STR ());
Vector <string> imglist;
The image name is stored in vector while
(file>>temp_imgname)
{
imglist.pushback (temp_imgname);
}
File.close ();
2
Use _findfirst, _findnext to get all file names
string Temp_imgname;
Long hfile = 0;//file handle
_finddata_t fileinfo;//file information
vector<string> imglist
if (hfile = _findfirst (m_strimageset+ "\\*", &fileinfo))!= -1)//m_strimageset is the variable I created earlier. Folder path
{do
{if
((Fileinfo.attrib & _a_subdir))
{
continue;//if it is a directory skip
}
else
{
Imglist.push_back (temp_imgname);
}
while (_findnext (hfile, &fileinfo) = = 0);
_findclose (hfile);
}
3 Using Finder to get
Win32_find_data Findfiledata;
int finder = 1;
CString m_strimageset_t = m_strimageset + "\\*.*";)//m_strimageset is a variable that I built before. The folder path
CString m_strimageset_t1 = M_strimageset + "\";
string imgname_temp;
Vector <string> imglist;
HANDLE hfind = FindFirstFile (m_strimageset_t, &findfiledata);
if (hfind = = Invalid_handle_value)
{
printf ("INVALID File HANDLE. GetLastError reports%d\n ", GetLastError ());
return;
}
else
{while
(Finder)
{
if (_tcscmp (findfiledata.cfilename,_t (".")) ==0) | | (_TCSCMP (findfiledata.cfilename,_t ("..")) ==0)//filter The default two folders
in the explorer. {
finder = FindNextFile (hfind,&findfiledata);
Continue;
}
else
{
temp_imgname = findfiledata.cfilename;
Imglist.pushback (temp_imgname);
}} FindClose (hfind);