By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,843 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

Dump Directory

P: 4
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.
Sep 17 '06 #1
Share this Question
Share on Google+
3 Replies


P: 61
Refer to dir.h and there you will get all the functionalities you needed.
Sep 18 '06 #2

P: 4
smk
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. #include "windows.h"
  4.  
  5. int
  6. main(int argc, char *argv[])
  7. {
  8.   WIN32_FIND_DATA FindFileData;
  9.   HANDLE hFind;
  10.  
  11.   printf ("Target file is %s.\n", argv[1]);
  12.  
  13.   hFind = FindFirstFile(argv[1], &FindFileData);
  14.  
  15.   if (hFind == INVALID_HANDLE_VALUE) {
  16.     printf ("Invalid File Handle. Get Last Error reports %d\n", GetLastError ());
  17.   } else {
  18.     printf ("The first file found is %s\n", FindFileData.cFileName);
  19.     FindClose(hFind);
  20.   }
  21.  
  22.   return (0);
  23. }
  24.  
  25.  
Sep 18 '06 #3

P: 4
Thank you very much !
Really big help !
Sep 18 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.