Re: viewing files in a directory

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Relvinian (m_at_msn.com)
Date: 06/07/04


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



Relevant Pages

  • Re: O_DIRECT question
    ... the disk isn't a good idea IMHO. ... There is a reason that read and write return the ... fsync between both sets of writes, but that will flush any other ... The large buffer size really has little to do with it, ...
    (Linux-Kernel)
  • Re: [Newbie Question] Magic Numbers dangerous?
    ... > reason can be documented with a well-chosen variable name. ... it's generally a matter of taking a guess. ... where memory is typically allocated in pages of a power of two in size. ... ideal buffer sizes, then most of us haven't yet been informed. ...
    (comp.lang.java.programmer)
  • Re: sharing memory with non-children
    ... > program that uses shared memory and semaphores to make a pseudo-pipe ... If you STREAM the data from one process to the another, ... necessarily need a big buffer. ... > is no good reason to do so. ...
    (comp.unix.programmer)
  • Re: [Newbie Question] Magic Numbers dangerous?
    ... >> reason can be documented with a well-chosen variable name. ... > buffer sizes, it's generally a matter of taking a guess. ... > the guess is a power of two, because it works better with MMU/paging ...
    (comp.lang.java.programmer)