Seriously, you're going to an awful lot of trouble to avoid using the library. There's no need to reinvent the wheel, just download boost.filesystem and be done with it. It has a much nicer API if you're writing in C++ anyway.
Besides, there's an awful lot of good, useful stuff in boost.
Cross platform directory list
Please don't drag in boost::filesystem just to provide this single functionality, that would be a dependency pain and add to the filesize of your project needlessly.
Since Windows is the only OS that needs bespoke code, I typically use the standard POSIX code on all operating systems and then a simple dirent.h API shim for windows.
Such as...
http://slam6d.sourceforge.net/html/doxygen/dirent_8h_source.html
or
http://users.cis.fiu.edu/~weiss/cop4338_sum07/dirent.h
or
http://softagalleria.net/dirent.php
I think that it is also provided when using GCC on Windows (Mingw), but it is also definitely provided by Cygwin.
Since Windows is the only OS that needs bespoke code, I typically use the standard POSIX code on all operating systems and then a simple dirent.h API shim for windows.
Such as...
http://slam6d.sourceforge.net/html/doxygen/dirent_8h_source.html
or
http://users.cis.fiu.edu/~weiss/cop4338_sum07/dirent.h
or
http://softagalleria.net/dirent.php
I think that it is also provided when using GCC on Windows (Mingw), but it is also definitely provided by Cygwin.
Please don't drag in boost::filesystem just to provide this single functionality
Right, because when you iterate over the contents of a directory that's all you're ever going to want to do with the file system.
Oh wait....
I need a crossplatform function to list a directory and then do something on the files inside (delete all files from there or copy files to another directory).
Meh, have fun reinventing the wheel, I'll be over here getting work done.
Well for deleting a file, there is a function in the C standard library for that: remove(). However, none of the C standard library, C++ standard library or POSIX have a function for copying a file. boost::filesystem, the Windows API and OS X have functions to copy files, though only boost::filesystem is portable. Linux also has a sendfile() function which can be used to copy files, but requires file descriptors instead of file names, but its semantics differ from other *nix sendfile() implementations. It is specifically listed to be non-portable in the kernel documentation.
Right, because when you iterate over the contents of a directory that's all you're ever going to want to do with the file system.
Gee, I wonder those 3 dirent.h libraries I listed above even exist then.
Perhaps to iterate over the files in a directory and read them? Perhaps using std::ifstream... or maybe we should drag in some boost stuff just to read a simple file too. ;)
Actually, since we are dragging in large unnecessary deps, perhaps we should drag in wxWidgets and use wxFile::read...
[quote name='Karsten_' timestamp='1353977091' post='5004367']
Please don't drag in boost::filesystem just to provide this single functionality
Right, because when you iterate over the contents of a directory that's all you're ever going to want to do with the file system.
[/quote]
Believe it or not, sometimes some of us just want to look for a particular file so we can open it and read its contents.
Believe it or not, sometimes some of us just want to look for a particular file so we can open it and read its contents.
oh FFS....
Oh wait....
[quote name='Acharis' timestamp='1353947969' post='5004227']
I need a crossplatform function to list a directory and then do something on the files inside (delete all files from there or copy files to another directory).
[/quote]
However, none of the C standard library, C++ standard library or POSIX have a function for copying a file.
Try reading the thread next time.
Actually, since we are dragging in large unnecessary deps, perhaps we should drag in wxWidgets and use wxFile::read...
Oh teh noes, however shall my application (which, let's not forget, is running on a pc, not some embedded device or console) cope with adding an extra 135kb dll?
boost.filesystem is a small library that's purpose built for dealing with exactly the kind of job the OP wants to do. So you can drop the ridiculous strawman.
It is this kind of mentality which causes games on Linux to drag in half the package repository.
I hate it when developers do that.
On Windows it is common practice to ship all the .dlls, but Linux package management has a very different approach.
I hate it when developers do that.
On Windows it is common practice to ship all the .dlls, but Linux package management has a very different approach.
Boost::filesystem can be linked statically, so this whole "extra dependency" issue is a total red herring.
Also, let's all calm down with the melodrama a bit, please.
Also, let's all calm down with the melodrama a bit, please.
It is still a large compile time dependency.
I.e if the game ever gets included in a continuous integration or ports system it does start to matter.
I.e Quake 3 compared to a very simple chess game. Quake 3 will take much less resources.
http://www.freebsd.org/cgi/ports.cgi?query=ioquake3-1.36_11&stype=name&sektion=all
http://www.freebsd.org/cgi/ports.cgi?query=glchess-1.0.6_6&stype=all&sektion=games
While I don't really care enough to argue, I would still go for the dirent.h solution every time.
I.e if the game ever gets included in a continuous integration or ports system it does start to matter.
I.e Quake 3 compared to a very simple chess game. Quake 3 will take much less resources.
http://www.freebsd.org/cgi/ports.cgi?query=ioquake3-1.36_11&stype=name&sektion=all
http://www.freebsd.org/cgi/ports.cgi?query=glchess-1.0.6_6&stype=all&sektion=games
While I don't really care enough to argue, I would still go for the dirent.h solution every time.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement