c++实现文件夹遍历

在windows下可以通过_findfirst()_findnext()实现对文件的遍历和操作

// intptr_t 32位下位int 64位下位long long
intptr_t _findfirst( const char *fileName, struct _finddata_t *fileData );
// 调用成功返回一个唯一编号(句柄),失败返回-1
// fileName 文件名称  支持通配符
// _fileData 文件信息 后面会解释这个结构体
int _findnext( long _findHandle, struct _finddata_t *fileData ); 
// _findHandle  _findfirst得到的句柄
// findData 文件信息
int _findclose( long handle ); 

_finddata_t在win下区分32位和64位 实质内容一致

struct __finddata64_t
{
    unsigned    attrib;
    __time64_t  time_create;    // -1 for FAT file systems
    __time64_t  time_access;    // -1 for FAT file systems
    __time64_t  time_write;
    __int64     size;
    char        name[260];
};
struct _finddata32_t
{
    unsigned    attrib;  // 文件属性  后面会解释
    __time32_t  time_create;  // 文件创建时间
    __time32_t  time_access;  // 文件最后一次访问时间
    __time32_t  time_write;  // 文件最后一次被写时间
    _fsize_t    size;  // 文件大小
    char        name[260];  // 文件名称
};
// File attribute constants for the _findfirst() family of functions
#define _A_NORMAL 0x00 // Normal file - No read/write restrictions 正常
#define _A_RDONLY 0x01 // Read only file  只读
#define _A_HIDDEN 0x02 // Hidden file  隐藏
#define _A_SYSTEM 0x04 // System file  系统
#define _A_SUBDIR 0x10 // Subdirectory  子文件夹
#define _A_ARCH   0x20 // Archive file  存档
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值