user-0 提问: findfirst findnext函数

回复:
user: user-0
content: system函数好像也不安全吧

user: user-1
content: 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命令不会。   Linux下使用ls命令。

user: user-1
content: http://www.linuxidc.com/Linux/2011-05/36580.htm

user: user-1
content: _findfirst, _findfirsti64, _wfindfirst, _wfindfirsti64 Provides information about the first instance of a filename that matches the file specified in the filespec argument.  long _findfirst( char *filespec, struct _finddata_t *fileinfo );  __int64 _findfirsti64( char *filespec, struct _finddata_t *fileinfo );  long _wfindfirst( wchar_t *filespec, struct _wfinddata_t *fileinfo );  __int64 _wfindfirsti64( wchar_t *filespec, struct _wfinddata_t *fileinfo );  Function Required Header Compatibility  _findfirst <io.h> Win 95, Win NT  _findfirsti64 <io.h> Win 95, Win NT  _wfindfirst <io.h> or <wchar.h> Win NT  _wfindfirsti64 <io.h> or <wchar.h> Win NT    For additional compatibility information, see Compatibility in the Introduction.  Libraries  LIBC.LIB Single thread static library, retail version  LIBCMT.LIB Multithread static library, retail version  MSVCRT.LIB Import library for MSVCRT.DLL, retail version    Return Value  If successful, _findfirst and _wfindfirst return a unique search handle identifying the file or group of files matching the filespec specification, which can be used in a subsequent call to _findnext or _wfindnext, respectively, or to _findclose. Otherwise, _findfirst and _wfindfirst return –1 and set errno to one of the following values:  ENOENT  File specification that could not be matched  EINVAL  Invalid filename specification  Parameters  filespec  Target file specification (may include wildcards)  fileinfo  File information buffer  Generic-Text Routine Mappings  TCHAR.H Routine  _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined  _tfindfirst _findfirst _findfirst _wfindfirst  _tfindfirsti64 _findfirsti64 _findfirsti64 _wfindfirsti64    System Calls Routines |  _find, _wfind Function Overview _findnext, _findnexti64, _wfindnext, _wfindnexti64 Find the next name, if any, that matches the filespec argument in a previous call to _findfirst, and then alters the fileinfo structure contents accordingly.  int _findnext( long handle, struct _finddata_t *fileinfo );  __int64 _findnexti64( long handle, struct _finddata_t *fileinfo );  int _wfindnext( long handle, struct _wfinddata_t *fileinfo );  __int64 _wfindnexti64( long handle, struct _wfinddata_t *fileinfo );  Function Required Header Compatibility  _findnext <io.h> Win 95, Win NT  _findnexti64 <io.h> Win 95, Win NT  _wfindnext <io.h> or <wchar.h> Win NT  _wfindnexti64 <io.h> or <wchar.h> Win NT    For additional compatibility information, see Compatibility in the Introduction.  Libraries  LIBC.LIB Single thread static library, retail version  LIBCMT.LIB Multithread static library, retail version  MSVCRT.LIB Import library for MSVCRT.DLL, retail version    Return Value  If successful, _findnext and _wfindnext return 0. Otherwise, they return –1 and set errno to ENOENT, indicating that no more matching files could be found.  Parameters  handle  Search handle returned by a previous call to _findfirst  fileinfo  File information buffer  Generic-Text Routine Mappings  TCHAR.H Routine  _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined  _tfindnext _findnext _findnext _wfindnext  _tfindnexti64 _findnexti64 _findnexti64 _wfindnexti64    System Calls Routines |  _find, _wfind Function Overview

user: user-2
content: dir.h没有这个文件吧。