findfirst findnext函数

elesun8 2014-12-29 09:56:36
/* 在程序目录下查找指定的文件,若查找找则打印出文件名 */
/* findfirst findnext函数应用程序 */

VC windows Linux gcc都有可能用到
问题:编译时找不到findfirst findnext函数,dir.h里面没有findfirst findnext函数



/* findnext example */
#include <stdio.h>
#include <dir.h>
//两个函数需要定义一个结构体来存储函数返回的数据。结构体如下:
struct ffblk
{
char ff_reserved[21]; /*DOS保留字*/
char ff_attrib; /*文件属性*/
int ff_ftime; /*文件时间*/
int ff_fdate; /*文件日期*/
long ff_fsize; /*文件长度*/
char ff_name[13]; /*文件名*/
}
//将结构体中的ff_name[13]显示出来即可。
void main(void)
{
struct ffblk ffblk;
int done;
printf("Directory listing of *.*\n");
done = findfirst("*.*",&ffblk,0);
while (!done)
{
printf(" %s\n", ffblk.ff_name);
done = findnext(&ffblk);
}
}
...全文
213 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
elesun8 2015-01-06
  • 打赏
  • 举报
回复
system函数好像也不安全吧
赵4老师 2014-12-30
  • 打赏
  • 举报
回复
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命令。
赵4老师 2014-12-30
  • 打赏
  • 举报
回复
_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
sprawling 2014-12-29
  • 打赏
  • 举报
回复
dir.h没有这个文件吧。

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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