Re: viewing files in a directory
From: Relvinian (m_at_msn.com)
Date: 06/07/04
- Next message: Relvinian: "Re: using .c files in mfc"
- Previous message: francis: "using .c files in mfc"
- In reply to: Joseph M. Newcomer: "Re: viewing files in a directory"
- Next in thread: Joseph M. Newcomer: "Re: viewing files in a directory"
- Reply: Joseph M. Newcomer: "Re: viewing files in a directory"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 6 Jun 2004 22:38:31 -0600
As per my example, just example code. I myself would never use a hard coded
path of ANY type. Whether it be c:\\windows, c:\\winnt, etc. I would do
c:\\ though as a starting but also, then again, I would probably use API
calls to get a list of available devices too.
But this is an example for him to expand on. As for the *.* you mentioned,
that is good only for the current directory (what ever that may be). That's
about as bad as hard coding c:\\windows.
Relv
PS - the reason I did show that is because you can take the prologue code
before the do-while loop and make necessary adjustments for it to recursive
directory searching.
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:ftk7c0dqoc7snfsefsripuagtk4612somv@4ax.com...
>
> Note that you should never code C:\Windows as a path in your program. If
you need to find
> the windows directory, you would call GetWindowsDirectory. It will NOT
always be called
> C:\Windows, and depending on that would be a fatal error.
>
> In addition, in the example shown, there is no reason to copy the string
to a buffer just
> so you can give the buffer address. For example, it is valid to write
>
> HANDLE hFile = ::FindFirstFile(_T("*.*"), &dirInfo);
>
> joe
>
> On Sun, 6 Jun 2004 19:27:03 -0600, "Relvinian" <m@msn.com> wrote:
>
> >Here's a short loop you can modify to your liking to process the contents
of
> >a given directory
> >
> >WIN32_FIND_DATA dirInfo;
> >
> >TCHAR szDirectory[_MAX_PATH];
> >_tcscpy(szDirectory, _T("c:\\windows\\*.*"));
> >
> >
> > HANDLE hFile = ::FindFirstFile(szDirectory, &dirInfo);
> > if (hFile != INVALID_HANDLE_VALUE)
> > {
> > do
> > {
> > // do something with dirInfo here
> > } while (::FindNextFile(hFile, &dirInfo));
> > }
> > ::FindClose(hFile);
> >
> >Relv
> >
> >"Inbar" <anonymous@discussions.microsoft.com> wrote in message
> >news:F4FE24CB-285B-45B2-BEF8-9BF234223C58@microsoft.com...
> >> I would like to run a function I have on all the files in a given
> >directory.
> >> I looked in the HELP on the Directory class and in the examples they
use:
> >> #using <mscorlib.dll>
> >>
> >> using namespace System;
> >> using namespace System::IO;
> >> using namespace System::Collections;
> >>
> >> But when I try to compile, it doesn't know those namespaces.
> >>
> >> And the rest of the script is:
> >> String* fileEntries[] = Directory::GetFiles(targetDirectory);
> >> IEnumerator* files = fileEntries->GetEnumerator();
> >> while (files->MoveNext()) {
> >> //Here I call my function
> >> }
> >>
> >> Is there another way to do this?
> >>
> >> Thanks
> >
>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
- Next message: Relvinian: "Re: using .c files in mfc"
- Previous message: francis: "using .c files in mfc"
- In reply to: Joseph M. Newcomer: "Re: viewing files in a directory"
- Next in thread: Joseph M. Newcomer: "Re: viewing files in a directory"
- Reply: Joseph M. Newcomer: "Re: viewing files in a directory"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|