递归遍历文件

// 函数功能:递归遍历文件
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <io.h>
int nFileNum;
// 函数功能:浏览文件
void scanfile(char* pPath, char* pName)
{
 char strFileName[256];
 nFileNum++;
 strcpy(strFileName, pPath);
 strcat(strFileName, pName);
 printf("%s/n", strFileName);
}
// 函数功能:浏览目录,递归
void scandir(char *strCurPath)
{
 char strTemp[2048];
 struct _finddata_t ffblk;
 int nReturn = 0;
 strcpy(strTemp, strCurPath);
 strcat(strTemp, "*.*");
 long lHandle = long(_findfirst(strTemp, &ffblk));
 while (lHandle != -1 && nReturn != -1)
 {
  if(strcmp(ffblk.name, ".") == 0 || strcmp(ffblk.name, "..") == 0)
  {
   nReturn = _findnext(lHandle, &ffblk);
   continue;
  }
  if (ffblk.attrib & _A_SUBDIR)
  {
   // Is Dir
   strcpy(strTemp, strCurPath);
   strcat(strTemp, ffblk.name);
   strcat(strTemp, "//");
   scandir(strTemp);
  }
  else
  {
   // Is File
   scanfile(strCurPath, ffblk.name);
  }
  nReturn = _findnext(lHandle, &ffblk);
 }
 _findclose(lHandle);
}

void main()
{
 nFileNum = 0;
 scandir("c://");
printf("/nTotal files: %d/n", nFileNum);
}

递归遍历文件

文章链接: https://www.mfisp.com/15125.html

文章标题:递归遍历文件

文章版权:梦飞科技所发布的内容,部分为原创文章,转载请注明来源,网络转载文章如有侵权请联系我们!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
建站教程投稿分享

字符串倒序

2022-12-29 23:59:57

建站教程投稿分享

卸载DLL模块

2022-12-30 0:04:40

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
客户经理
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索

梦飞科技 - 最新云主机促销服务器租用优惠