#define _AFXDLL
#include <afxwin.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int _Finder(LPCTSTR pstr)
{
CFileFind finder ;
vector<CString> svec;
CString strWildcard(pstr) ;
strWildcard += _T("\\*.*") ;
BOOL bWorking = finder.FindFile( strWildcard ) ;
int i = 0 ;
while(bWorking)//如果还有文件存在就执行下面的
{
bWorking = finder.FindNextFile() ;
if ( finder.IsDots() ) //如果是. 或者.. 就continue
{
bWorking = finder.FindNextFile() ;
continue ;
}
//一般文件及文件夹
BOOL bisDir = finder.IsDirectory() ;
if( bisDir )
{ //是文件夹
CString repath = finder.GetFilePath() ;
wchar_t* sz=(wchar_t *)repath.GetBuffer(repath.GetLength());
wcout << sz <<endl;
}
else
{//是文件
//输出文件路径
CString repath = finder.GetFilePath() ; //eg return c:\myhtml\myfile.txt
wchar_t* sz=(wchar_t *)repath.GetBuffer(repath.GetLength());
wcout << sz <<endl;
//输出文件名
CString filename = finder.GetFileName();
wchar_t* fn = (wchar_t *)filename.GetBuffer(filename.GetLength());
wcout << fn <<endl;
}
}//end while
finder.Close() ;
return 1 ;
}
#include <string>
int main()
{
CString filePath("D:\\train\\");
_Finder(filePath);
return 0;
}
#include <afxwin.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int _Finder(LPCTSTR pstr)
{
CFileFind finder ;
vector<CString> svec;
CString strWildcard(pstr) ;
strWildcard += _T("\\*.*") ;
BOOL bWorking = finder.FindFile( strWildcard ) ;
int i = 0 ;
while(bWorking)//如果还有文件存在就执行下面的
{
bWorking = finder.FindNextFile() ;
if ( finder.IsDots() ) //如果是. 或者.. 就continue
{
bWorking = finder.FindNextFile() ;
continue ;
}
//一般文件及文件夹
BOOL bisDir = finder.IsDirectory() ;
if( bisDir )
{ //是文件夹
CString repath = finder.GetFilePath() ;
wchar_t* sz=(wchar_t *)repath.GetBuffer(repath.GetLength());
wcout << sz <<endl;
}
else
{//是文件
//输出文件路径
CString repath = finder.GetFilePath() ; //eg return c:\myhtml\myfile.txt
wchar_t* sz=(wchar_t *)repath.GetBuffer(repath.GetLength());
wcout << sz <<endl;
//输出文件名
CString filename = finder.GetFileName();
wchar_t* fn = (wchar_t *)filename.GetBuffer(filename.GetLength());
wcout << fn <<endl;
}
}//end while
finder.Close() ;
return 1 ;
}
#include <string>
int main()
{
CString filePath("D:\\train\\");
_Finder(filePath);
return 0;
}