
在做图像处理中通常要对图像
文件连续读取,因此需要
遍历整个文件夹中的文件。不要着急在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.HBOOL 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
}
评论列表(0条)