Thread: Directory Functions

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    19

    Directory Functions

    I'm trying to write code so that I can search through a folder and determine the last date that each file was modified. I have the code to determine the date that the files were modified, but I dont have code to get the filenames from the folder, the filenames are not always the same. So far, I have the following code.

    Code:
      struct ffblk finfo;
      char array[100][20];  /* array to store 100 file names */
      int done;
      int counter = 0 , i;
      printf("File names stored in the array:\n");
      done = findfirst("*.*",&finfo,0);
      while (!done)
      {
         strcpy(array[counter++] , finfo.ff_name);
         done = findnext(&finfo);
      }
      for(i = 0; i < counter ; i++)
      printf("%s\n" ,array[i]);
      getch();
    The problem I have is that I was supposed to use the dir.h header file. However, my Visual Studio version doesnt have that header file. So I cant use the findfirst or the findnext functions. So does anyone know where I can download the dir.h header file. Or is there another way that I can get the filenames from a directory?

  2. #2
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Or is there another way that I can get the filenames from a directory?
    This is system specific. Maybe with some luck you could find a generic implementation who targets multiple-platforms, but i don't know any.

    As for your dir.h missing header file, well i don't know much what you are talking about, but even if you could find the dir.h file over the internet, you would still need the "object" file associated with it, which could be a lot more complicated to find...

    If you are on windows, you could use the Win32 API. Here's a link that gives you the possiblity of file/directory manipulation.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    In particular, you will want FindFirstFile(), FindNextFile() and FindClose().

    The code you posted looks like something from Borland C or some other DOS compiler.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    As for your dir.h missing header file, well i don't know much what you are talking about, but even if you could find the dir.h file over the internet, you would still need the "object" file associated with it, which could be a lot more complicated to find...
    Indeed. http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    You might also want to have a look at this FAQ: http://faq.cprogramming.com/cgi-bin/...&id=1044780608

    As a side note, I believe MSVC does have findfirst(), as _findfirst().
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is it legal to have functions within functions?
    By Programmer_P in forum C++ Programming
    Replies: 13
    Last Post: 05-25-2009, 11:21 PM
  2. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  3. Directory reading trouble
    By samGwilliam in forum Linux Programming
    Replies: 0
    Last Post: 03-10-2002, 09:43 AM
  4. Getting back to the top of the directory
    By samGwilliam in forum Linux Programming
    Replies: 2
    Last Post: 02-25-2002, 04:49 PM
  5. The Site Directory
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-22-2002, 08:19 PM