在VC环境下怎样遍历文件夹中的文件

在VC环境下怎样遍历文件夹中的文件,第1张

在做图像处理中通常要对图像文件连续读取,因此需要遍历整个文件夹中的文件。不要着急在IO.H、WCHAR.H中提供了_finddata_t, _wfinddata_t, _wfinddatai64_t 结构,通过_findfirst可以得到满足条件的第一个文件的句柄,如下:long_findfirst(char*filespec,struct_finddata_t*fileinfo),然后你可以使用_findnext函数得到用_findfirst的句柄后的文件指针,如此就可以遍历所有满足条件的文件。long hFileif( (hFile = _findfirst( LPCTSTR(pathWild), &c_file )) == -1L ){::AfxMessageBox("No image files in current directory!/n" ) }else{do { AfxGetMainWnd()->SetWindowText(c_file.name)} while (_findnext(hFile, &c_file) == 0)}_findclose(hFile)对了,别忘了在你的工程中包括头文件IO.H

BOOL EmuFilesToDes(const char * path)

{

CString cs(path)

WIN32_FIND_DATA data

cs += "\\*.*"

HANDLE handle = FindFirstFile((LPCSTR)cs,&data)

BOOL ret = (BOOL)handle

while(ret)

{

if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)

{

if(data.cFileName[0] != '.') //IsDirectory

{

cs = path

cs +="\\"

cs += data.cFileName

EmuFilesToDes((LPCSTR)cs)

}

}

else //is a file

{

{

cs = path

cs +="\\"

cs += data.cFileName

OutputDebugstring(cs)

}

}

ret = FindNextFile(handle,&data)

}

FindClose(handle)

return bSuccess

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/tougao/11680296.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存