Directory Contents C++

This is a discussion on Directory Contents C++ within the C++ Programming forums, part of the General Programming Boards category; Im writing a game right now and I want it to get the contents of a directory, mainly *.sav files ...

  1. #1
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195

    Directory Contents C++

    Im writing a game right now and I want it to get the contents of a directory, mainly *.sav files and then put it all into an array of sorts. My main priority is to get this code cross platform - Linux, Windows, Mac etc. Does anyone know of such code?

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I doubt you'll find anything in the regard that is very cross-platform, as each system will use it's own filesystem. What I recommend is that you isolate the platform-dependant parts of your program into one file, and then you just have to change one tiny part of your program for each build.

  3. #3
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    Ok, in that case i might have to put the two different code snippents in a bunch of #ifdef #endif statements. Where can i find code that does this for linux and windows, those are my two main platforms.

  4. #4
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    For *nix platforms, do a search for dirent.h and ftw.h. That should get you started with navigating and reading directories for linux.

  5. #5
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    Use the Boost filesystem libraries.

    http://www.boost.org

  6. #6
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    I prefer not to jump into any other libraries that i have no experience with. I rather write my own. I take it using ftw.h and dirent.h i can get a list of files from within a direcotyr on *nix. how about windows, is there a equivalent (without using windows.h)?

  7. #7
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  2. Using sys/stat.h and listing directory contents in C...
    By smoothdogg00 in forum C Programming
    Replies: 2
    Last Post: 03-14-2006, 02:11 AM
  3. reading the contents of a directory
    By Unregistered in forum C++ Programming
    Replies: 10
    Last Post: 04-15-2002, 11:19 AM
  4. Directory contents in C....
    By eebling in forum C Programming
    Replies: 4
    Last Post: 04-11-2002, 12:27 PM
  5. read directory contents
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 04-04-2002, 11:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21