Skip to main content
gamedev.net
🔒 Locked

Finding Files

Started by Jubulani Nov 2, 2004 at 12:50 PM 3 replies 750+ views
Original Post
Jubulani
Jubulani
Is there a platform agnostic way to find the names of all the files in the current directory? What I have been doing up till now is redirecting the output from 'dir' to a file, reading it in and them deleting it. Obviously this only works on Windows. Similar things could be done for other platforms, but I would like to know if there is an easier way. I also need to know the directory the program is actually in. This doesn't coincide with the current directory, and I don't know how to find this out. The win32 API has a function GetModuleFileName that will tell me this, but how could I achieve the same thing under linux (for example)? Linux noob trying to port (and improve) a program I wrote a while ago.
Nytegard
Nytegard
I'm assuming you're using C/C++.

Unfortunately, no. Not every computer that has a C compiler has a directory structure, let alone a standard directory structure.

Microsoft aside, if you're going for Linux and other non Windows platforms, include dirent.h, and lookup the functions opendir & readdir.
MonkeyCookie
MonkeyCookie
The Boost filesystem library is a good one:

http://www.boost.org/libs/filesystem/doc/index.htm

You can get the current directory with boost::filesystem::current_path()
Jubulani
Jubulani
Sorry, I did forget to say I was using C++.

The boost library looks like it will be very helpful, as does dirent.h.

Thanks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.