Reading a directory and it's sub-directories


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Reading a directory and it's sub-directories

  1. #1
    Doug Farrell Guest

    Reading a directory and it's sub-directories


    Hi,

    I'm having problems creating a class that will read the files in a directory
    and all of it's sub-directories. What I want is to call something like this:

    CDirRead dirRead("C:\\tmp\\*.*");
    filename = dirRead.first();

    while (filename != "") {
    process(filename);
    filename = dirRead.next();
    }

    so I can retrieve filenames one by one and process them, including files
    in subdirectories. So the CDirRead class has to maintain state information
    between calls and perhaps be recursive as well. Anyone have any suggestions
    or help?

    Thanks in advance,
    Doug

  2. #2
    Max Voronoy Guest

    Re: Reading a directory and it's sub-directories


    "Doug Farrell" <writeson@earthlink.net> wrote:
    >
    >Hi,
    >
    >I'm having problems creating a class that will read the files in a directory
    >and all of it's sub-directories. What I want is to call something like this:
    >
    >CDirRead dirRead("C:\\tmp\\*.*");
    >filename = dirRead.first();
    >
    >while (filename != "") {
    > process(filename);
    > filename = dirRead.next();
    >}
    >
    >so I can retrieve filenames one by one and process them, including files
    >in subdirectories. So the CDirRead class has to maintain state information
    >between calls and perhaps be recursive as well. Anyone have any suggestions
    >or help?
    >
    >Thanks in advance,
    >Doug


    Hi Doug!
    Best for Win32 is usage of pair: FindFirstFile/FindNextFile - you can see
    sample in MSDN's samples VC98\mfc\internet\mfcie\mainfrm.cpp
    If you want to build cross-platform code, use pair findfirst/findnext routine
    from <io.h>

    Sincerely yours!
    Max Voronoy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center