Directory contents in C....

This is a discussion on Directory contents in C.... within the C Programming forums, part of the General Programming Boards category; Hi all, I was wondering if anyone could tell me how to return all the file names of a specified ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    1

    Directory contents in C....

    Hi all, I was wondering if anyone could tell me how to return all the file names of a specified directory into an array. I just wanna write up a simple copy program, but I need the file names of the files in the dir....I'm using C....If anyOne can Help, I'd appreciate it...

  2. #2
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    well if you are using visual C++ then this is the function you want

    long _findfirst( char *filespec, struct _finddata_t *fileinfo );

    Provides information about the first instance of a filename that matches the file specified in the filespec argument.

    for the filespec parameter you can pass it "*.*" to find files. Read up on microcraps documentaion on it and you will figure it all out.
    also as a side note......you will have to set up a loop kinda like this...
    Code:
    long FileHandle = 0;
    _finddata_t FileData;   //Structure to stores file data.
    
    /* Not sure what is in FileData right now. all I know is that it
        doesn't contain the data I want. */
    FileHandle = _findfirst("*.*",&FileData);  
    
    if(FileHandle != -1)
    {
        int Result = 0,
        FileCount = 0;  
          
        /* Same with this one.
        Result = _findnext(FileHandle,&FileData);     
      
        /* This Filedata has the first file in the Directory now.  
        Result = _findnext(FileHandle,&FileData);
        while(Result == 0)
        {
             /* Do other stuff*/
             /* Get next file. If no more files, result == -1 */
             Result = _findnext(FileHandle,&FileData);
        } 
    }
    Hope this helps ya somewhat. If all else fails check mocrocraps help documents or borlands depending on your compiler.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  3. #3
    Unregistered
    Guest
    If you are using DOS i suggest you take a look at the program FileLister at AcmeSofties
    http://www.geocities.com/acmesofties
    in the disc and file section.
    Deepak
    deepak-p@eth.net

  4. #4
    Unregistered
    Guest
    Take a look at the program FileLister in the Disc anf File section of AcmeSofties
    http://www.geocities.com/acmesofties
    Deepak
    deepak-p@eth.net

  5. #5
    CG_Pimp
    Guest

    reply

    thanks guys, I'm sure one of those will work, I just have to sit down and apply it.....gotta go to work now!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  2. Using sys/stat.h and listing directory contents in C...
    By smoothdogg00 in forum C Programming
    Replies: 2
    Last Post: 03-14-2006, 02:11 AM
  3. Directory Contents C++
    By Mastadex in forum C++ Programming
    Replies: 6
    Last Post: 03-01-2005, 02:21 AM
  4. reading the contents of a directory
    By Unregistered in forum C++ Programming
    Replies: 10
    Last Post: 04-15-2002, 11:19 AM
  5. read directory contents
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 04-04-2002, 11:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21