Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Walk through directories

Status
Not open for further replies.

Buraje

Technical User
Mar 19, 2001
14
0
0
DE
Hi there,

I need to open and walk through directories in C.
Can I use fopen like I'd do for files?
And how?
After haviong done this, I'd like to open all(!) files
in a directory (one after another or however) to seek
for keywords in them.

Thanks,

Buraje
 
Also,
what does getenv() do?
regards,
Buraje
 
Hi,
Depending on your compiler look up 'findfirst(...)' and 'findnext(...)' or FindFirstFile(...) etc.
Good Luck,
Pappy Pappy
You learn somrthing everyday.
 
C has no native support for directory opening/traversing, so how you do this depends on the implementation. If you're in a DOS/Windows environment, take a look at findfirst() and findnext(). For *nix environments take a look at opendir() and readdir()

getenv() returns a pointer to a string that matches an environment variable specified in the 1st argument. For example, you might do:

char *home=getenv("PATH");

To get the current execution path.

Russ
bobbitts@hotmail.com
 
With Unix you can use the function ftw ("File Tree Wallk)

For Details read the Manual

hnd
hasso55@yahoo.com

 
Actually I need both - so I will have to modify
my programs.
Thank you very much fo these tips.
Buraje

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top