CFileFind 某些目录扫不到

心希盼 2014-05-27 02:34:00
我使用CFileFind进行文件遍历扫描,结果有些文件夹明明是在的,但是CFileFind却对此视而不见。
...全文
230 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-05-29
  • 打赏
  • 举报
回复
在cmd窗口里面输入以下命令 attrib "C:\Users\zl\AppData\LocalLow\SogouPY\Components\Picface\BigShow" dir "C:\Users\zl\AppData\LocalLow\SogouPY\Components\Picface\BigShow" dir /ads "C:\Users\zl\AppData\LocalLow\SogouPY\Components\Picface\BigShow" dir /adh "C:\Users\zl\AppData\LocalLow\SogouPY\Components\Picface\BigShow" dir /adsh "C:\Users\zl\AppData\LocalLow\SogouPY\Components\Picface\BigShow" 再试试? 计算机组成原理→DOS命令→汇编语言→C语言(不包括C++)、代码书写规范→数据结构、编译原理、操作系统→计算机网络、数据库原理、正则表达式→其它语言(包括C++)、架构……
zilaishuichina 2014-05-29
  • 打赏
  • 举报
回复
如果是这样的路径,说明这个路径确实不存在 比如可能BigShow这个文件夹实际上是 Big Show (中间多一个空格,或者B之前还有一个空格,或者是w之后还有一个空格,而lz你可能忽略了这个空格) lz可以按照目录顺序一级一级的往下尝试 C:\ C:\Users C:\Users\zl C:\Users\zl\AppData C:\Users\zl\AppData\LocalLow 看看到哪一级目录的时候开始报错的
赵4老师 2014-05-29
  • 打赏
  • 举报
回复
从attrib "C:\Users\zl\AppData\LocalLow\SogouPY\Components\Picface\BigShow"的结果中看其属性,必要的话调用 CFileFind::MatchesMask virtual BOOL MatchesMask( DWORD dwMask ) const; Return Value Nonzero if successful; otherwise 0. To get extended error information, call the Win32 functionGetLastError. Parameters dwMask Specifies one or more file attributes, identified in theWIN32_FIND_DATA structure, for the found file. To search for multiple attributes, use the bitwise OR (|) operator. Any combination of the following attributes is acceptable: FILE_ATTRIBUTE_ARCHIVE The file is an archive file. Applications use this attribute to mark files for backup or removal. FILE_ATTRIBUTE_COMPRESSED The file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is the default for newly created files and subdirectories. FILE_ATTRIBUTE_DIRECTORY The file is a directory. FILE_ATTRIBUTE_NORMAL The file has no other attributes set. This attribute is valid only if used alone. All other file attributes override this attribute. FILE_ATTRIBUTE_HIDDEN The file is hidden. It is not to be included in an ordinary directory listing. FILE_ATTRIBUTE_READONLY The file is read only. Applications can read the file but cannot write to it or delete it. FILE_ATTRIBUTE_SYSTEM The file is part of or is used exclusively by the operating system. FILE_ATTRIBUTE_TEMPORARY The file is being used for temporary storage. Applications should write to the file only if absolutely necessary. Most of the file’s data remains in memory without being flushed to the media because the file will soon be deleted. Remarks Call this member function to test the file attributes on the found file. CFileFind Overview | Class Members | Hierarchy Chart See Also CFileFind::IsDots, CFileFind::IsReadOnly, CFileFind::IsDirectory, CFileFind::IsCompressed, CFileFind::IsSystem, CFileFind::IsHidden, CFileFind::IsTemporary, CFileFind::IsNormal, CFileFind::IsArchived
CFileFind finder;
BOOL bWorking = finder.FindFile(_T("C:\\Users\\zl\\AppData\\LocalLow\\SogouPY\\Components\\Picface\\BigShow\\*.*"));
while (bWorking)
{
   bWorking = finder.FindNextFile();
   cout << (LPCTSTR) finder.GetFileName() << endl;
}

心希盼 2014-05-29
  • 打赏
  • 举报
回复
引用 17 楼 zhao4zhong1 的回复:
在cmd窗口里面输入以下命令 attrib "C:\Users\zl\AppData\LocalLow\SogouPY\Components\Picface\BigShow" dir "C:\Users\zl\AppData\LocalLow\SogouPY\Components\Picface\BigShow" dir /ads "C:\Users\zl\AppData\LocalLow\SogouPY\Components\Picface\BigShow" dir /adh "C:\Users\zl\AppData\LocalLow\SogouPY\Components\Picface\BigShow" dir /adsh "C:\Users\zl\AppData\LocalLow\SogouPY\Components\Picface\BigShow" 再试试? 计算机组成原理→DOS命令→汇编语言→C语言(不包括C++)、代码书写规范→数据结构、编译原理、操作系统→计算机网络、数据库原理、正则表达式→其它语言(包括C++)、架构……
那个我试过咯,是行的。 因为这个目录CFileFind找不到,要给客户一个合理的解释。比如说windows保护不能访问之类的,但是它返回给我的是Path not found。这个比较怪异。。。
zilaishuichina 2014-05-28
  • 打赏
  • 举报
回复
引用 4 楼 Stan1989 的回复:
[quote=引用 2 楼 zilaishuichina 的回复:] 遍历可以使用API:FindFirstFile,FindNextFile
首先很感谢你的回答。你说的两个API我也试过,也是不行。GetLastError返回的是3.PATH not found。[/quote] 那么你的PATH 是什么样子的呢,是不是有特殊字符呢,是不是汉字字符集不对呢?
schlafenhamster 2014-05-28
  • 打赏
  • 举报
回复
虚拟目录(如 垃圾箱,我的计算机。。。) 用 FindFirst 是找不到的,
赵4老师 2014-05-28
  • 打赏
  • 举报
回复
提醒:MD5需要你自己编程或调用其它命令行工具或库自己计算得出。
赵4老师 2014-05-28
  • 打赏
  • 举报
回复
system("dir /b /a-d c:\\*.* >d:\\allfiles.txt"); //读文件d:\\allfiles.txt的内容即C:\\下所有文件的名字 system("dir /b /a-d /s c:\\*.* >d:\\allfilesinsub.txt"); //读文件d:\\allfilesinsub.txt的内容即C:\\下所有文件的名字包含子目录 system("dir /b /ad c:\\*.* >d:\\alldirs.txt"); //读文件d:\\alldirs.txt的内容即C:\\下所有子目录的名字 请记住,能用shell命令获取文件、文件夹信息或者操作文件、文件夹最好用shell命令获取或者操作,而不要用各种API获取或者操作,因为当遇到非法文件夹名或非法文件名或非法文件长度、非法文件日期、压缩文件、链接文件、稀疏文件……等各种意料之外的情况时,API会处理的不全面或陷入死循环,而shell命令不会
赵4老师 2014-05-28
  • 打赏
  • 举报
回复
path not found可能是因为 你路径名中有空格汉字等字符时没用半角双引号括住 函数要求pathname用多字节字符串,你传递了Unicode字符串,或者反之 你路径名中该用\结果你传了\\,或者反之 你路径名中有比如\n\r\"*/:<>?\\|等非法字符 你路径名超长 ……
心希盼 2014-05-28
  • 打赏
  • 举报
回复
引用 13 楼 zilaishuichina 的回复:
[quote=引用 4 楼 Stan1989 的回复:] [quote=引用 2 楼 zilaishuichina 的回复:] 遍历可以使用API:FindFirstFile,FindNextFile
首先很感谢你的回答。你说的两个API我也试过,也是不行。GetLastError返回的是3.PATH not found。[/quote] 那么你的PATH 是什么样子的呢,是不是有特殊字符呢,是不是汉字字符集不对呢? [/quote] C:\Users\zl\AppData\LocalLow\SogouPY\Components\Picface\BigShow 就是上面这个路径,PATH not found 但我不确定你有没有这个路径
心希盼 2014-05-28
  • 打赏
  • 举报
回复
引用 12 楼 schlafenhamster 的回复:
虚拟目录(如 垃圾箱,我的计算机。。。) 用 FindFirst 是找不到的,
垃圾箱这些能够读出来的
心希盼 2014-05-27
  • 打赏
  • 举报
回复
引用 6 楼 zhao4zhong1 的回复:
CFileFind::MatchesMask virtual BOOL MatchesMask( DWORD dwMask ) const; Return Value Nonzero if successful; otherwise 0. To get extended error information, call the Win32 functionGetLastError. Parameters dwMask Specifies one or more file attributes, identified in theWIN32_FIND_DATA structure, for the found file. To search for multiple attributes, use the bitwise OR (|) operator. Any combination of the following attributes is acceptable: FILE_ATTRIBUTE_ARCHIVE The file is an archive file. Applications use this attribute to mark files for backup or removal. FILE_ATTRIBUTE_COMPRESSED The file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is the default for newly created files and subdirectories. FILE_ATTRIBUTE_DIRECTORY The file is a directory. FILE_ATTRIBUTE_NORMAL The file has no other attributes set. This attribute is valid only if used alone. All other file attributes override this attribute. FILE_ATTRIBUTE_HIDDEN The file is hidden. It is not to be included in an ordinary directory listing. FILE_ATTRIBUTE_READONLY The file is read only. Applications can read the file but cannot write to it or delete it. FILE_ATTRIBUTE_SYSTEM The file is part of or is used exclusively by the operating system. FILE_ATTRIBUTE_TEMPORARY The file is being used for temporary storage. Applications should write to the file only if absolutely necessary. Most of the file’s data remains in memory without being flushed to the media because the file will soon be deleted. Remarks Call this member function to test the file attributes on the found file. CFileFind Overview | Class Members | Hierarchy Chart See Also CFileFind::IsDots, CFileFind::IsReadOnly, CFileFind::IsDirectory, CFileFind::IsCompressed, CFileFind::IsSystem, CFileFind::IsHidden, CFileFind::IsTemporary, CFileFind::IsNormal, CFileFind::IsArchived
。。。,怎么说呢,我要的不是这个,我扫描的时候需要比较文件时间,类型,大小,MD5等属性。所以这个函数还是不能满足这些比较功能。 其实我只想知道CFileFind为什么不能扫到某一些特地的目录。 通过GetLastError,我知道了有一个原因是access denied,这个我好理解。 另外一个原因是path not found,这个我很难理解,路径明明在那边,为什么会返回这个错误。
赵4老师 2014-05-27
  • 打赏
  • 举报
回复
WIN32_FIND_DATA The WIN32_FIND_DATA structure describes a file found by the FindFirstFile, FindFirstFileEx, or FindNextFile function. typedef struct _WIN32_FIND_DATA { // wfd DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[ MAX_PATH ]; TCHAR cAlternateFileName[ 14 ]; } WIN32_FIND_DATA; Members dwFileAttributes Specifies the file attributes of the file found. This member can be one or more of the following values: Attribute Meaning FILE_ATTRIBUTE_ARCHIVE The file or directory is an archive file or directory. Applications use this attribute to mark files for backup or removal. FILE_ATTRIBUTE_COMPRESSED The file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is the default for newly created files and subdirectories. FILE_ATTRIBUTE_DIRECTORY The handle identifies a directory. FILE_ATTRIBUTE_ENCRYPTED The file or directory is encrypted. For a file, this means that all data streams are encrypted. For a directory, this means that encryption is the default for newly created files and subdirectories. FILE_ATTRIBUTE_HIDDEN The file or directory is hidden. It is not included in an ordinary directory listing. FILE_ATTRIBUTE_NORMAL The file or directory has no other attributes set. This attribute is valid only if used alone. FILE_ATTRIBUTE_OFFLINE The file data is not immediately available. Indicates that the file data has been physically moved to offline storage. FILE_ATTRIBUTE_READONLY The file or directory is read-only. Applications can read the file but cannot write to it or delete it. In the case of a directory, applications cannot delete it. FILE_ATTRIBUTE_REPARSE_POINT The file has an associated reparse point. FILE_ATTRIBUTE_SPARSE_FILE The file is a sparse file. FILE_ATTRIBUTE_SYSTEM The file or directory is part of the operating system or is used exclusively by the operating system. FILE_ATTRIBUTE_TEMPORARY The file is being used for temporary storage. File systems attempt to keep all of the data in memory for quicker access, rather than flushing it back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed. ftCreationTime Specifies a FILETIME structure containing the time the file was created. FindFirstFile and FindNextFile report file times in Coordinated Universal Time (UTC) format. These functions set the FILETIME members to zero if the file system containing the file does not support this time member. You can use the FileTimeToLocalFileTime function to convert from UTC to local time, and then use the FileTimeToSystemTime function to convert the local time to a SYSTEMTIME structure containing individual members for the month, day, year, weekday, hour, minute, second, and millisecond. ftLastAccessTime Specifies a FILETIME structure containing the time that the file was last accessed. The time is in UTC format; the FILETIME members are zero if the file system does not support this time member. ftLastWriteTime Specifies a FILETIME structure containing the time that the file was last written to. The time is in UTC format; the FILETIME members are zero if the file system does not support this time member. nFileSizeHigh Specifies the high-order DWORD value of the file size, in bytes. This value is zero unless the file size is greater than MAXDWORD. The size of the file is equal to (nFileSizeHigh * MAXDWORD) + nFileSizeLow. nFileSizeLow Specifies the low-order DWORD value of the file size, in bytes. dwReserved0 If the dwFileAttributes member includes the FILE_ATTRIBUTE_REPARSE_POINT attribute, this member specifies the reparse tag. Otherwise, this value is undefined and should not be used. dwReserved1 Reserved for future use. cFileName A null-terminated string that is the name of the file. cAlternateFileName A null-terminated string that is an alternative name for the file. This name is in the classic 8.3 (filename.ext) filename format. Remarks If a file has a long filename, the complete name appears in the cFileName field, and the 8.3 format truncated version of the name appears in the cAlternateFileName field. Otherwise, cAlternateFileName is empty. As an alternative, you can use the GetShortPathName function to find the 8.3 format version of a filename. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in winbase.h. Unicode: Defined as Unicode and ANSI structures. See Also File I/O Overview, File Structures, FINDEX_INFO_LEVELS FindFirstFile, FindFirstFileEx, FindNextFile, FILETIME, FileTimeToLocalFileTime, FileTimeToSystemTime, GetShortPathName
赵4老师 2014-05-27
  • 打赏
  • 举报
回复
CFileFind::MatchesMask virtual BOOL MatchesMask( DWORD dwMask ) const; Return Value Nonzero if successful; otherwise 0. To get extended error information, call the Win32 functionGetLastError. Parameters dwMask Specifies one or more file attributes, identified in theWIN32_FIND_DATA structure, for the found file. To search for multiple attributes, use the bitwise OR (|) operator. Any combination of the following attributes is acceptable: FILE_ATTRIBUTE_ARCHIVE The file is an archive file. Applications use this attribute to mark files for backup or removal. FILE_ATTRIBUTE_COMPRESSED The file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is the default for newly created files and subdirectories. FILE_ATTRIBUTE_DIRECTORY The file is a directory. FILE_ATTRIBUTE_NORMAL The file has no other attributes set. This attribute is valid only if used alone. All other file attributes override this attribute. FILE_ATTRIBUTE_HIDDEN The file is hidden. It is not to be included in an ordinary directory listing. FILE_ATTRIBUTE_READONLY The file is read only. Applications can read the file but cannot write to it or delete it. FILE_ATTRIBUTE_SYSTEM The file is part of or is used exclusively by the operating system. FILE_ATTRIBUTE_TEMPORARY The file is being used for temporary storage. Applications should write to the file only if absolutely necessary. Most of the file’s data remains in memory without being flushed to the media because the file will soon be deleted. Remarks Call this member function to test the file attributes on the found file. CFileFind Overview | Class Members | Hierarchy Chart See Also CFileFind::IsDots, CFileFind::IsReadOnly, CFileFind::IsDirectory, CFileFind::IsCompressed, CFileFind::IsSystem, CFileFind::IsHidden, CFileFind::IsTemporary, CFileFind::IsNormal, CFileFind::IsArchived
心希盼 2014-05-27
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
system("dir /b /a-d c:\\*.* >d:\\allfiles.txt"); //读文件d:\\allfiles.txt的内容即C:\\下所有文件的名字 system("dir /b /a-d /s c:\\*.* >d:\\allfilesinsub.txt"); //读文件d:\\allfilesinsub.txt的内容即C:\\下所有文件的名字包含子目录 system("dir /b /ad c:\\*.* >d:\\alldirs.txt"); //读文件d:\\alldirs.txt的内容即C:\\下所有子目录的名字 请记住,能用shell命令获取文件、文件夹信息或者操作文件、文件夹最好用shell命令获取或者操作,而不要用各种API获取或者操作,因为当遇到非法文件夹名或非法文件名或非法文件长度、非法文件日期、压缩文件、链接文件、稀疏文件……等各种意料之外的情况时,API会处理的不全面或陷入死循环,而shell命令不会。
还有我很想知道CFileFind为什么不能扫到那些特定目录。
心希盼 2014-05-27
  • 打赏
  • 举报
回复
引用 2 楼 zilaishuichina 的回复:
遍历可以使用API:FindFirstFile,FindNextFile
首先很感谢你的回答。你说的两个API我也试过,也是不行。GetLastError返回的是3.PATH not found。
心希盼 2014-05-27
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
system("dir /b /a-d c:\\*.* >d:\\allfiles.txt"); //读文件d:\\allfiles.txt的内容即C:\\下所有文件的名字 system("dir /b /a-d /s c:\\*.* >d:\\allfilesinsub.txt"); //读文件d:\\allfilesinsub.txt的内容即C:\\下所有文件的名字包含子目录 system("dir /b /ad c:\\*.* >d:\\alldirs.txt"); //读文件d:\\alldirs.txt的内容即C:\\下所有子目录的名字 请记住,能用shell命令获取文件、文件夹信息或者操作文件、文件夹最好用shell命令获取或者操作,而不要用各种API获取或者操作,因为当遇到非法文件夹名或非法文件名或非法文件长度、非法文件日期、压缩文件、链接文件、稀疏文件……等各种意料之外的情况时,API会处理的不全面或陷入死循环,而shell命令不会。
恩,谢谢,这是一个好方法。 但是有一点,CFileFind我能够很方便的获取到文件的时间属性和大小,不需要再去做额外的操作进行获取。而我现在的遍历就需要这些信息。
zilaishuichina 2014-05-27
  • 打赏
  • 举报
回复
遍历可以使用API:FindFirstFile,FindNextFile
赵4老师 2014-05-27
  • 打赏
  • 举报
回复
system("dir /b /a-d c:\\*.* >d:\\allfiles.txt"); //读文件d:\\allfiles.txt的内容即C:\\下所有文件的名字 system("dir /b /a-d /s c:\\*.* >d:\\allfilesinsub.txt"); //读文件d:\\allfilesinsub.txt的内容即C:\\下所有文件的名字包含子目录 system("dir /b /ad c:\\*.* >d:\\alldirs.txt"); //读文件d:\\alldirs.txt的内容即C:\\下所有子目录的名字 请记住,能用shell命令获取文件、文件夹信息或者操作文件、文件夹最好用shell命令获取或者操作,而不要用各种API获取或者操作,因为当遇到非法文件夹名或非法文件名或非法文件长度、非法文件日期、压缩文件、链接文件、稀疏文件……等各种意料之外的情况时,API会处理的不全面或陷入死循环,而shell命令不会。

64,439

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧