我想将一个文件夹内的所有.txt文件名都放到一个文本里。我提问的时候看了下相关问题,都是C#或VB的。具体方法能不能介绍一下。谢谢!
解决方案 »
- VS2005的MSDN如何查找MFC类库信息?
- CToolTipCtrl如何改变背景颜色!!!!!
- 问ADO的存储过程的入门级问题
- 图形平铺并且不刷新掉的问题.
- 手工加的类(基类 CFrameWnd),手工加的函数OnPaint(),设断点怎么不响应呀。
- 对话框上添加视
- 老板出3000块让大家买书,大家最近读过什么好的,给个建议吧
- C++ Users Journal十年合订本和MSDN Magazine2002合订本共享
- 敬请高手回答:怎么从dll工程的辅助线程向界面弹出对话框?
- 明天去人才市场,给点建议吧,我是非计算机专业的,想 找程序开发这样的工作
- CHtmlView 怎么显示我构造的CString
- vc6.0中怎么改动文件名?
或者你想有一个直接完成的方法?命令行也可以用CreateProcess运行下列命令
dir *.txt > result.txt
WIN32_FIND_DATA fd = {0};
_tcscpy(tsTemp, strFolder);
_tcscat(tsTemp, _T("*.*"));
hFile = ::FindFirstFile(tsTemp, &fd);
if(hFile != INVALID_HANDLE_VALUE)
{
do
{
if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if(_tcscmp(fd.cFileName, _T(".")) == 0 || _tcscmp(fd.cFileName, _T("..")) == 0)
{
continue;
}
...
...
}
while(::FindNextFile(hFile,&fd));
::FindClose(hFile); 这段代码可以遍历strFolder目录下的所有文件
{
char szFind[MAX_PATH];
WIN32_FIND_DATA FindFileData; strcpy(szFind,lpPath);
strcat(szFind,"\\*.*"); HANDLE hFind=::FindFirstFile(szFind,&FindFileData);
if(INVALID_HANDLE_VALUE == hFind) return;
while(TRUE)
{
if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(FindFileData.cFileName[0]!='.')
{
strcpy(szFile,lpPath);
strcat(szFile,"\\");
strcat(szFile,FindFileData.cFileName);
find(szFile);
}
}
else
{
cout << FindFileData.cFileName;
}
if(!FindNextFile(hFind,&FindFileData)) break;
}
FindClose(hFind);
}
文章出处:DIY部落(http://www.diybl.com/course/3_program/vc/vc_js/20081010/149673.html)
不知道是否有其它方法,
看楼下
{
try
{
CFileFind finder;
char ttt[ 1024 ] = "";
HTREEITEM tmp;
CString strWildcard( str_path ); if( deep >= 2 )
{
return;
}
//CTreeCtrl *t = ( CTreeCtrl * )( this->GetDlgItem( IDC_TREE1 ) );
strWildcard += _T( "\\*.*" );
TRACE( strWildcard );
TRACE( g____crlf ); // start working for files
BOOL bWorking = finder.FindFile( strWildcard ); while ( bWorking )
{
bWorking = finder.FindNextFile();
if ( finder.IsDots() )
continue;
if( NULL == tree )
{
tmp = treectrl->InsertItem( finder.GetFilePath() );
}
else
{
memset( ttt, 0, sizeof( ttt ) );
strcat( ttt, finder.GetFileName() ); //文件名+扩展名
//strcat( ttt, finder.GetFileTitle() ); //文件名
strcat( ttt, " " ); //16个
strcat( ttt, " " ); //16个
strcat( ttt, " " ); //16个
strcat( ttt, " " ); //16个
strcat( ttt, " " ); //16个
strcat( ttt, " " ); //16个
ttt[ SPLITSIZE ] = 0;
strcat( ttt, "(" );
strcat( ttt, finder.GetFilePath() );
strcat( ttt, ")" );
tmp = treectrl->InsertItem( ttt, tree );
}
if ( finder.IsDirectory() )
{
GlobalEnumFile( treectrl, finder.GetFilePath(), tmp, deep + 1 );
}
} finder.Close();
}
catch( ... )
{
throw;
}
SortTree( treectrl, treectrl->GetRootItem() );
}一个参考。
请问是怎么给他制定文件的路径的,直接看代码我还是看不清楚,水平有限。
哦 明白了 是在finder.FindFile( )里面设置文件路径