SFML community forums

Help => General => Topic started by: The Terminator on July 28, 2013, 04:47:11 am

Title: Finding script files
Post by: The Terminator on July 28, 2013, 04:47:11 am
Hi everyone. I have a quick question about file system traversal. Basically, I've created a basic scripting language for my game engine, and I want the game engine to search through a folder and find all the script files. Then, I want to have an option on my main menu to enable/disable the "mod." Do you guys know any good libraries or built in features that can accommodate to this? I heard boost had something similar to this.

Thanks
Title: Re: Finding script files
Post by: Nexus on July 28, 2013, 09:01:55 am
I want the game engine to search through a folder and find all the script files.
Boost.Filesystem

Then, I want to have an option on my main menu to enable/disable the "mod."
GUI interface and bool variable
Title: Re: Finding script files
Post by: FRex on July 28, 2013, 09:41:16 am
Boost.Filesystem
God no :( , this is so not meant for games and will just be confuzling to fit in that role.
The games centric filesystem that is greatly portable, based on dooms filesystems, easy to use(everything is UTF-8, the end), safe for malicious scripts(there is NO way to go outside of your games root folder and read or write to rest of the system using it, so after cutting out all fstreams and FILEs, engine is sanitized and no script can be danger to outside world) and makes underlying filesystem completely transparent(no wchar_t on windows nonsense) after initializing is: PhysicsFS. Oh, and it turns zips, 7zips and few 90s games archives(id techs paks, build engine grps etc.) into part of its virtual filesystem tree and makes it so that later added folders and archives will cover up files with same paths from earlier ones so modding, changing, default and user settings etc. are very easy to achieve.
Title: Re: Finding script files
Post by: Nexus on July 28, 2013, 10:26:43 am
God no :( , this is so not meant for games and will just be confuzling to fit in that role.
It is meant for file systems, which are also used in games.

You are right that PhysicsFS has some very specific features for games. But sometimes plain file systems are still required, e.g. when you want to load/save something in any directory. Also, PhysicsFS is C, but it's really well-designed, object-orientated C. And it's great that some archives are embedded; unfortunately it's not possible to encrypt them.
Title: Re: Finding script files
Post by: Perde on July 28, 2013, 06:04:44 pm
This is what I was using to solve a similar problem. I didn't see any reason to use a full-blown file system api, just to get the files in a specific directory.

#include <dirent.h>

DIR *dir;
struct dirent *ent;
if ((dir = opendir ("c:\\src\\")) != NULL) {
  /* print all the files and directories within directory */
  while ((ent = readdir (dir)) != NULL) {
    printf ("%s\n", ent->d_name);
  }
  closedir (dir);
} else {
  /* could not open directory */
  perror ("");
  return EXIT_FAILURE;
}

Also happens to be the very first result from a google search on "list files in directory c++".
http://stackoverflow.com/questions/612097/how-can-i-get-a-list-of-files-in-a-directory-using-c-or-c
Title: Re: Finding script files
Post by: FRex on July 28, 2013, 06:10:02 pm
dirent.h is part of posix and isn't always there on windows, it's not there for some visual studios(but there is a separate .h that emulates it)