Thread: how to list files in a directory, to then manipulate each file.

  1. #1
    Registered User
    Join Date
    Mar 2002

    Question how to list files in a directory, to then manipulate each file.

    I want to automaticaly manipulate each file in a directory. First thing is to be able ( and I have searched long nights unsuccessfully) to list files in a directory, then treat one at a time.
    I'm writting a DOS console application, C++, win2000.

  2. #2
    I'm Back
    Join Date
    Dec 2001
    you'll find the dir.h header has a lot of file/dir manip stuff

    use findnextfile or something like that, getcwd, chdir etc functions to use files and dirs.

    hope this gets you started.

  3. #3
    Registered User
    Join Date
    Mar 2002
    HEY! Thanks........just the name of it looks promissing (dir.h)
    I'm sure it's not in any of my books. I'll have to wait till I get to work to check it out... in any case...thank you very much.

  4. #4
    Registered User Sunny's Avatar
    Join Date
    Nov 2001

    Red face RE: DIr/Stuff

    Ok... I bumped into the same challenge recently... First of all, you'll need to find a way to get the file-name of each file ( sometimes directories pretend to be files too). To do this, you can use functions such as 'findfirst()' and 'findnext()' or any other funtion. Then you'll have to use a buffer to store the filename of each individual file. This is though. I'm using linked lists now, but it sometimes gives me problems when I bump into more than 100 or so files in one dir... so you c... If you do come out with anything better than me, please post a reply, coz i'm really interested in finding out...


  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    As a matter of fact, directories are files. They are just treated differently when encountered. DOS implements numerous disk I/O functions like findnext() and findfirst() via int 21h. Check out RBIL to view these interrupts or you can try to get your hands on a DOS tech ref. The disk I/O functions are far too numerous for me to list them here.

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    I know BASIC has a statement which will print (to the screen) a directory of a folder (just like typing DIR), but I have never been able to either manipulate so you could access that data as variables in a program, or found the C/ASM equivalent.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-27-2008, 11:24 PM
  2. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 10:16 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM