VC++能用的,遍历文件夹及子文件夹文件的代码

参考了论坛里高手们的代码,自己做了小修改~~~

#include <stdio.h>
#include <afx.h>
#include <afxwin.h>
#include <iostream>
#include <string>
using namespace std;
 void RecursiveFindFile(CString strPath)
{
   CFileFind ff;
   BOOL bFind = ff.FindFile(strPath + "\\*.*");
 
   while(bFind)
   {
      bFind = ff.FindNextFile();
      if (ff.IsDots() || ff.IsSystem() || ff.IsHidden())
         continue;
       
      if (ff.IsDirectory())
      {
         RecursiveFindFile(ff.GetFilePath());
      }
      else
      {
         CString strFileName = ff.GetFilePath();
         AfxMessageBox(strFileName);
      }
   }
}



int main()
{
	string pathin;
	CString spath;
	cout<<"Please enter the path (Like C:\\):"<<endl;
	while(cin>>pathin)
	{
		spath=pathin.c_str();
		break;
	}
	RecursiveFindFile(spath);
system("pause");
return 0;
}
当输入需要遍历的路径后,开始以消息框的形式给出文件名称,大家可以拿去改一改,用来保存文件名及文件信息。
注意,后来测试了一下,当文件路径含有空格时,因为是string类型保存路径,所以会出现错误,可以修改一下输入的方式,采用getline()函数。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值