-
July 10th, 2013, 03:34 AM
#1
Wildcards! Which one?
Im working on a simple file list program that list folders and files using CFileFind. Heres how the program goes!
1. User types a directory in a edit box
2. Presses button and files and folders get listed.
**If user wants to go back a directory
1. Presses the back button
And the back button is my problem. I know the problem is the Wildcard format. Im using a CString with a addition "/.." eg....(CString cp = m_Directory + "/..");
I tried CString cp = m_Directory + "/.." + "*.*" and vice versa with no luck
My question is how do I add a "*.*" to the CString cp? If I don't add "*.*", I know that all the files will not get listed.Only one folder gets listed when I press the back button
Can you help me with this problem.
-THX
oh yeah. Here is the code im using for the back button
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.IsDots ()) continue;
m_b.AddString(OneFile.GetFileName ());
GetDlgItem(IDC_EDIT3)->SetWindowText(OneFile.GetRoot());
}
OneFile.Close ();
}
-
July 10th, 2013, 03:41 AM
#2
Re: Wildcards! Which one?
Victor Nijegorodov
-
July 10th, 2013, 04:30 AM
#3
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.
-
July 10th, 2013, 04:37 AM
#4
Re: Wildcards! Which one?
From MSDN:
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:"));
}
Victor Nijegorodov
-
July 10th, 2013, 09:26 AM
#5
Re: Wildcards! Which one?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|