怎样获得搜索到文件的路径。解决方案
怎样获得搜索到文件的路径。
??
------解决方案--------------------
GetPathName()
------解决方案--------------------
msdn的例子:
#include <afxwin.h>
#include <iostream>
using namespace std;
void Recurse(LPCTSTR pstr)
{
CFileFind finder;
// build a string with wildcards
CString strWildcard(pstr);
strWildcard += _T( "\\*.* ");
// start working for files
BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking)
{
bWorking = finder.FindNextFile();
// skip . and .. files; otherwise, we 'd
// recur infinitely!
if (finder.IsDots())
continue;
// if it 's a directory, recursively search it
if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
cout < < (LPCTSTR) str < < endl;
Recurse(str);
}
}
finder.Close();
}
void main()
{
if (!AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0))
cout < < "panic! " < < endl;
else
Recurse(_T( "C: "));
}
------解决方案--------------------
GetFilePath();
------解决方案--------------------
用access(filename, 0) == 0 可以從硬盤上找到文件名為filename 的文件是否存在。
自然也能找到路徑
??
------解决方案--------------------
GetPathName()
------解决方案--------------------
msdn的例子:
#include <afxwin.h>
#include <iostream>
using namespace std;
void Recurse(LPCTSTR pstr)
{
CFileFind finder;
// build a string with wildcards
CString strWildcard(pstr);
strWildcard += _T( "\\*.* ");
// start working for files
BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking)
{
bWorking = finder.FindNextFile();
// skip . and .. files; otherwise, we 'd
// recur infinitely!
if (finder.IsDots())
continue;
// if it 's a directory, recursively search it
if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
cout < < (LPCTSTR) str < < endl;
Recurse(str);
}
}
finder.Close();
}
void main()
{
if (!AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0))
cout < < "panic! " < < endl;
else
Recurse(_T( "C: "));
}
------解决方案--------------------
GetFilePath();
------解决方案--------------------
用access(filename, 0) == 0 可以從硬盤上找到文件名為filename 的文件是否存在。
自然也能找到路徑