Re: Wildcards! Which one?
Re: Wildcards! Which one?
Dang, man its hard...even looked up the IsDirectory on msdn with no luck
heres some code that I came up...jerry rigging and still does not work entirely..i get double folders of the directory im in.
Code:
void CAlDlg::OnButton1()
{
m_b.ResetContent();
UpdateData(true);
CString oke = m_o;
UpdateData(false);
CFileFind OneFile;
CString FileName, DirName;
BOOL BeWorking;
DirName = oke + "..";
BeWorking = OneFile.FindFile (DirName);
while (BeWorking)
{ BeWorking = OneFile.FindNextFile () ;
if(OneFile.IsDirectory() && OneFile.IsDots())
{
m_b.ResetContent();
}
m_b.AddString(OneFile.GetFileName ());
GetDlgItem(IDC_EDIT3)->SetWindowText(OneFile.GetRoot());
UpdateData(true);
BeWorking = OneFile.FindFile (m_o + "\\*.*");
while (BeWorking)
{
BeWorking = OneFile.FindNextFile () ;
m_b.AddString(OneFile.GetFileName ());
}
UpdateData(false);
}
OneFile.Close ();
}
Can someone tell me the proper way of getting the back button to work, to list all files.
Re: Wildcards! Which one?
From MSDN:
Quote:
Example
This small program recurses every directory on the C:\ drive and prints the name of the directory.
Code:
#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();
}
int main()
{
if (!AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0))
cout << "panic!" << endl;
else
Recurse(_T("C:"));
}
Re: Wildcards! Which one?
Quote:
Originally Posted by
vaas
Dang, man its hard...even looked up the IsDirectory on msdn with no luck
heres some code that I came up...jerry rigging and still does not work entirely..i get double folders of the directory im in.
One suggestion to make to you is that you first write simple programs that perform the basic task you're looking for.
Your code is a jumble of listbox calls, button calls, and other things totally unrelated with writing a function that recurses through a directory, causing confusion, not only to you, but it clutters the code so that others helping you have to filter out the unnecessary noise.
If you take a look at Victor's example, that is exactly what you should be writing first, making sure you are familiar and know how to use the CFileFind class. Once you know how to properly use it, then you apply it to the larger program.
Regards,
Paul McKenzie