[SDL] Filesystem routines

Gaetan de Menten ged at bugfactory.org
Tue Nov 11 01:06:02 PST 2003


You could use the excellent PhysicsFS library by Ryan C. Gordon which
does exactly what you need...

It can be found at:
http://www.icculus.org/physfs/

Hope it helps,
Gaetan.

On Tue, 2003-11-11 at 09:37, Stuart Bingë wrote:
> Hello everyone,
> 
> I've been using SDL now for several projects and so far I'm very happy 
> with it, so I wish to thank the authors for doing such a great job.
> 
> I have one issue with SDL, or should I say more of a `new feature' wish, 
> that I've been thinking about for a while. I must apologise if this has 
> been discussed before, however I've just signed up to this list, and 
> haven't had time to search the archives yet.
> 
> What I would like to see is a group of functions such as the following:
> 
> 
> SDL_FIND_FILE* SDL_FindFirst(char* path, char* filter);
> int SDL_FindNext(SDL_FIND_FILE* filerec);
> void SDL_FindClose(SDL_FIND_FILE* filerec);
> 
> 
> The purpose of which is to iterate through a list of files in a 
> specified directory. We already have standard functions in the various C 
> libraries to read and write files, however there is no real portable way 
> to search for files. The functions that I've described correspond very 
> closely to the Win32 way of iterating through files; from my experience 
> this is a very simple and clean way to do it, although there may be far 
> more efficient ways to do it. The POSIX way of opendir(), readdir() and 
> stat() is not that great, IMHO.
> 
> Here is a snippet of C code using the above functions that searches a 
> directory for a list of text files, to give an example of how they could 
> be used:
> 
> 
> SDL_FIND_FILE* f = SDL_FindFirst("./data/", "*.txt");
> if (!f) return;
> int found = 1;
> while (found) {
> 	if (SDL_IS_DIRECTORY(f)) { /* file is a directory */ };
> 	AddFileToList(f->name);
> 	/* etc ... */
> 	found = SDL_FindNext(f);	
> }
> SDL_FindClose(filerec);
> 
> 
> Why would you want this? Well, I'm thinking to use these in a setup such 
> as how Quake does things, where data files from later archives in an 
> alphabetically sorted list of archives override data files in earlier 
> archives (e.g. data files in ZZZ.pak override those in AAA.pak). 
> Currently there is no easy/portable way to search a given directory for 
> a list of files such as `*.pak'.
> 
> Problems with this? Of course. So far I've worked on Win32 and several 
> UNIX'es and the way they represent the filesystem is totally different, 
> to say nothing of the other platforms that SDL runs on. I would say that 
> these functions should take the easy route and pass on the path that 
> they are given to the underlying platform's `find file' functions, 
> perhaps only converting directory delimiters (e.g. from '/' to '\', 
> etc). Leave the problem of portablly representing paths to the user of 
> the functions; the only viable way to do it would be to use relative 
> paths, or perhaps load a base path from a config file.
> 
> While I'm on the topic of file-related routines, I'll also put forward 
> an idea for some additional functions, the purpose of which would be to 
> facilitate directory and file manipulation:
> 
> 
> char* SDL_GetWorkingDirectory();
> char* SDL_GetHomeDirectory();  // "~", "C:\Documents and Settings\User\ 
> My Documents\", etc
> int SDL_ChangeWorkingDirectory(char* newcwd);
> int SDL_CreateDirectory(char* dir);
> int SDL_DeletePath(char* dir);	// Used for files & dirs
> int SDL_RenamePath(char* old, char* new); // Used for files & dirs
> 
> 
> These are just rough ideas however, I'm primarily interested in the file 
> search routines. I would greatly appreciate feedback on all of this, as 
> I'm sure my ideas can be improved upon.
> 
> Thanks and Regards,
> Stuart Bingë
> 
> 
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl





More information about the SDL mailing list