Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to search for files

Credits go to CGamesPlay and LennyLen for helping out!
This thread is locked; no one can reply to it. rss feed Print
How to search for files
Kikaru
Member #7,616
August 2006
avatar

How should I go about searching for different files in a directory, such as all files of one extension, without user input?

CGamesPlay
Member #2,559
July 2002
avatar

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Kikaru
Member #7,616
August 2006
avatar

Thanks. Just one last question: with for_each_file_ex, is it possible to limit it to one directory, such as the same one as the .exe?

CGamesPlay
Member #2,559
July 2002
avatar

Yes. It doesn't recurse into subdirectories in the first place.

replace_filename, get_executable_name

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Kikaru
Member #7,616
August 2006
avatar

Ok. Thanks. So, to find .sav files in a folder named SAVES in the directory as my game, I would do this:

for_each_file_ex("SAVES//*.sav", ..., my_callback, ...);

?

LennyLen
Member #5,313
December 2004
avatar

Quote:

for_each_file_ex("SAVES//*.sav", ..., my_callback, ...);

Yes, except that you would specify the directory as "SAVES/*.sav" (or under DOS/Windows "SAVES\*.sav").

Kikaru
Member #7,616
August 2006
avatar

Oh. Yeah, I use windows and forgot which way the slashes went. ;D

Thanks for the help! :)

BAF
Member #2,981
December 2002
avatar

You might as well use /. It's more readable IMO because it doesn't require escaping, and it is cross-platform (unlike \).

Kikaru
Member #7,616
August 2006
avatar

'\\' is for windows. I don't think '/' works on windows though. :P

LennyLen
Member #5,313
December 2004
avatar

Quote:

I don't think '/' works on windows though

Yes it does.

Go to: