Sign in to follow this  
graveyard filla

how to search a directory for files ?

Recommended Posts

hi, im working on my map editor written in C++, OpenGL and SDL. ive recently got an input system working, where i could take keyboard input from the user (ie ask the user for a file to load /save).. anyway, i want to add to my load feature, where i display a list of the map files in the working directory (actually, not the ones in the directory the program will be in, its in maps/ , so i would want to load maps/filename.txt) how would i go about doing it? heres what ive come up with, but im hoping theres a better way.. have a text file calls map_names.txt. each time i save a map, i will open map_names, search for the map im about to save, if its not found, ill append the maps name at the end of this text file. then, when i go to load, ill open this text file, and ill display the names of the files... this sounds kind of hacky and was hoping theres a nicer way. thanks for any help!!

Share this post


Link to post
Share on other sites
mandrav    333
Under Windows you can use FindFirstFile(), FindNextFile() and FindClose(). Look them up in MSDN, they 're dead easy to use.
Under other platforms (like Linux) there are similar functions, but I can't recall them right now (I think it's scandir())...

HTH,
Yiannis.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this