Dump Directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sunnyko
    New Member
    • Aug 2006
    • 4

    Dump Directory

    I have many directorys and many files in each of them.
    I want to write a C program to read all these files and extract some important words inside them out. But there is a problem

    How can I access a directory in C program ?
    How can I change the directory to another directory ?

    How to get all the files' name in a specific directory ?

    Please help me.
    I really need your great help.
  • pukur123
    New Member
    • Sep 2006
    • 61

    #2
    Refer to dir.h and there you will get all the functionalities you needed.

    Comment

    • smk
      New Member
      • Sep 2006
      • 4

      #3
      Hi,

      Using FindFirstFile and FindNextFile functions you can browse through the directory tree and can get all the files names. These functions will return WIN32_FIND_DATA structure, which has the information about the file attributes.The below example will be helpfull.

      Code:
      
      #include "windows.h"
      
      int
      main(int argc, char *argv[])
      {
        WIN32_FIND_DATA FindFileData;
        HANDLE hFind;
      
        printf ("Target file is %s.\n", argv[1]);
      
        hFind = FindFirstFile(argv[1], &FindFileData);
      
        if (hFind == INVALID_HANDLE_VALUE) {
          printf ("Invalid File Handle. Get Last Error reports %d\n", GetLastError ());
        } else {
          printf ("The first file found is %s\n", FindFileData.cFileName);
          FindClose(hFind);
        }
      
        return (0);
      }

      Comment

      • sunnyko
        New Member
        • Aug 2006
        • 4

        #4
        Thank you very much !
        Really big help !

        Comment

        Working...