我現在用的是這getFiles函式來得到檔案的路徑名稱的,讀取的是中文的路徑
void getFiles(string path, vector<string>& files)
{
//檔案句柄
long hFile = 0;
//檔案資訊
struct _finddata_t fileinfo;
string p;
//搜索與指定的檔案名稱匹配的第一個實體,若成功則回傳第一個實體的句柄,否則回傳-1
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do //回圈整個檔案夾搜索
{
//如果是目錄,迭代之
//如果是檔案,加入串列
if ((fileinfo.attrib & _A_SUBDIR)) //目錄
{
//cout << fileinfo.name << endl;
if (strcmp(fileinfo.name, ".") == 1 && strcmp(fileinfo.name, "..") == 1)
{
files.push_back(fileinfo.name);
}
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
{
getFiles(p.assign(path).append("\\").append(fileinfo.name), files); //迭呼叫自身迭代搜索找到的目錄
}
}
else //檔案
{
//files.push_back(p.assign(path).append("\\").append(fileinfo.name) );
//cout << p.assign(path).append("\\").append(fileinfo.name )<< endl;
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
}
} while (_findnext(hFile, &fileinfo) == 0); // 查找下一個
//釋放由FindFirst分配的記憶體
_findclose(hFile);
}
}
在控制臺視窗上列印出來的像是這樣的:
檔案夾
i:/檔案夾/a_picture.jpg
i:/檔案夾/b_photo.jpg
i:/檔案夾/c_photo.jpg
i:/檔案夾/d_photo.jpg
我糾結的是輸出的檔案的順序,系統好像是按照首字母順序來的,有沒有什么辦法可以讓輸出的是這樣的呢?
檔案夾
i:/檔案夾/d_photo.jpg
i:/檔案夾/b_picture.jpg
i:/檔案夾/c_photo.jpg
i:/檔案夾/a_photo.jpg
也就這種可以無視首字母順序,按照自己的意愿的輸出,有沒有什么辦法可以解決呢? 謝謝了
uj5u.com熱心網友回復:
那你自己給排個序好了~uj5u.com熱心網友回復:
比如我想先輸出 d開頭的,然后是b開頭的,接著c開頭的,最后a開頭的轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/145289.html
標籤:基礎類
下一篇:【求助】把一個檔案夾下多個Excel檔案(每個檔案有多個sheet且名字不一樣)復制到模板里面,另存到指定檔案夾
