win32下遍历枚举文件夹(磁盘)里的文件

来源:互联网 发布:mac屏保 wordoftheday 编辑:程序博客网 时间:2024/04/28 21:36

deviceName可以是文件夹名字也可以是磁盘名如:C:\\等

void GetDevicefileName(const wstring deviceName,vector<wstring>& device_fileNames)

{
wstring pathTmp = deviceName + L"\\*.*";
wstring subPath ;
_wfinddata_t data;
long lFile = (long)_wfindfirst(pathTmp.c_str(),&data);
if(lFile == -1){
return;
}
while (_wfindnext(lFile,&data) == 0)
{
wstring name = data.name;
if(wstring(data.name) == L"."||wstring(data.name) == L".."){
continue;
}
if(data.attrib == 0x0010 || data.attrib == 0x002010){
subPath = deviceName;
subPath += L"\\";
subPath += data.name;
GetDevicefileName(subPath,device_fileNames);
}
else
{
wstring fileName = deviceName + L"\\" + wstring(data.name);
device_fileNames.push_back(fileName);
}
}
_findclose(lFile);
}
原创粉丝点击