CFileFind Problem. Don't search the Subdirs. [Solved]
-
My directory structure is Dir1 |---------file.exe |---------angle.txt |---------test.txt |---------Dir2 |________Dir3 My code works like it just find the .txt files under Dir1, never find files under Dir2, Dir3 etc. Please tell me what's wrong with my code.
void CWinSearchDlg::SearchInternal(LPCTSTR path, CStdioFile *file)
{
CFileFind finder;
TCHAR szWildcard[MAX_PATH] = {0};
_sntprintf(szWildcard, MAX_PATH, _T("%s"), path);PathAppend(szWildcard, \_T("\*.txt")); BOOL bWorking = finder.FindFile(szWildcard); while (bWorking) { bWorking = finder.FindNextFile(); //1 escape dot if (finder.IsDots()) continue; if (finder.IsDirectory()) { SearchInternal(finder.GetFilePath(), file); } //else is a file //Do my things here } finder.Close();
}
modified on Saturday, September 20, 2008 9:51 PM
-
My directory structure is Dir1 |---------file.exe |---------angle.txt |---------test.txt |---------Dir2 |________Dir3 My code works like it just find the .txt files under Dir1, never find files under Dir2, Dir3 etc. Please tell me what's wrong with my code.
void CWinSearchDlg::SearchInternal(LPCTSTR path, CStdioFile *file)
{
CFileFind finder;
TCHAR szWildcard[MAX_PATH] = {0};
_sntprintf(szWildcard, MAX_PATH, _T("%s"), path);PathAppend(szWildcard, \_T("\*.txt")); BOOL bWorking = finder.FindFile(szWildcard); while (bWorking) { bWorking = finder.FindNextFile(); //1 escape dot if (finder.IsDots()) continue; if (finder.IsDirectory()) { SearchInternal(finder.GetFilePath(), file); } //else is a file //Do my things here } finder.Close();
}
modified on Saturday, September 20, 2008 9:51 PM
OF course except CfileFind you can use of FindFirstFile/FindNextFile.
-
My directory structure is Dir1 |---------file.exe |---------angle.txt |---------test.txt |---------Dir2 |________Dir3 My code works like it just find the .txt files under Dir1, never find files under Dir2, Dir3 etc. Please tell me what's wrong with my code.
void CWinSearchDlg::SearchInternal(LPCTSTR path, CStdioFile *file)
{
CFileFind finder;
TCHAR szWildcard[MAX_PATH] = {0};
_sntprintf(szWildcard, MAX_PATH, _T("%s"), path);PathAppend(szWildcard, \_T("\*.txt")); BOOL bWorking = finder.FindFile(szWildcard); while (bWorking) { bWorking = finder.FindNextFile(); //1 escape dot if (finder.IsDots()) continue; if (finder.IsDirectory()) { SearchInternal(finder.GetFilePath(), file); } //else is a file //Do my things here } finder.Close();
}
modified on Saturday, September 20, 2008 9:51 PM
fantasy1215 wrote:
Please tell me what's wrong with my code.
Your wildcard is "*.txt". Your subdirectories don't have a .txt extension so they won't show up in the search. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
fantasy1215 wrote:
Please tell me what's wrong with my code.
Your wildcard is "*.txt". Your subdirectories don't have a .txt extension so they won't show up in the search. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
There are .txt files in Subdirs too.
-
There are .txt files in Subdirs too.
But the SubDirs will be Ignored because they do not have a '.txt' extension in their name. (For Still the best explanation about Command Line Parsing Rules, Look up any book about DOS 6.00). DOS may have died, but many of its parsing rules persist. :)
Bram van Kampen