Void getFiles (string path, vector& Files)
{
//file handle
Long hFile=0;
//file information
Struct _finddata_t the fileinfo;
String p;
//search with the specified file name matches the first instance, if successful, returns a handle to the first instance, otherwise return 1
If ((hFile=_findfirst (p.a ssign (path), append (" \ \ * "). The c_str (), & amp; The fileinfo))!=1)
{
Do//cycle entire folders search
{
//if it is a directory, iteration of the
//if the file, add list
If ((the fileinfo attrib & amp; _A_SUBDIR))//directory
{
//cout & lt;
If (STRCMP (the fileinfo. Name, "")==1 & amp; & The STRCMP (the fileinfo. The name ".. ")==1)
{
Files. The push_back (the fileinfo. Name);
}
If (STRCMP (the fileinfo. Name, "")!=0 & amp; & The STRCMP (the fileinfo. The name ".. ")!=0)
{
GetFiles (p.a ssign (path), append (" \ \ "), append (the fileinfo. Name), files).//idea calls itself an iterative search to find the directory
}
}
The else//file
{
//files. The push_back (p.a ssign (path), append (" \ \ "), append (the fileinfo. Name));
//cout & lt;
Files. The push_back (p.a ssign (path), append (" \ \ "), append (the fileinfo. Name));
}
} while (_findnext (hFile, & amp; The fileinfo)==0);//find next
//release by FindFirst allocated memory
_findclose (hFile);
}
}
Printed in the console window like this:
The folder
I:/folder/a_picture. JPG
I:/folder/b_photo. JPG
I:/folder/c_photo. JPG
I:/folder/d_photo. JPG
I've struggled with is the order of the output file, the system seems to be come in alphabetical order according to the first, is there any way can make the output is such?
The folder
I:/folder/d_photo. JPG
I:/folder/b_picture. JPG
I:/folder/c_photo. JPG
I:/folder/a_photo. JPG
Also in this order you can ignore the first letter, according to the wishes of their own output, is there any way we can solve? Thank you for the
CodePudding user response:
The rank order for yourself ok ~CodePudding user response:
I want to make the output of d beginning, for example, and then is the beginning of the b, then c at the beginning of, the last at the beginning of a