-
December 23rd, 2003, 01:20 AM
#1
get file names in a folder / directory
how do i get the file names of all the files in a folder / directory in c++?
-
December 23rd, 2003, 04:37 AM
#2
Re: get file names in a folder / directory
Originally posted by kalavathy
how do i get the file names of all the files in a folder / directory in c++?
There are no standard C++ functions to get the names of the files in a directory. You need to tell us the operating system and compiler you are using, since getting the names of the files all depend on compiler and OS.
If you want a cross-platform solution, you can investigate the boost libraries at www.boost.org. They have a file/directory class that works on various operating systems.
Regards,
Paul McKenzie
-
December 23rd, 2003, 05:12 AM
#3
In addition to Paul's correct answer...if you are using Windows, take a look at the following FAQ. It shows how one can do it in Windows, however, it basically can be easily ported to a different operating system/compiler since the way is still the same (except for the keywords probably)...
-
December 23rd, 2003, 07:12 AM
#4
Dear Andreas,
Although the code in the link that u mention is quite perfect, but I saw another thread, which mentioned a minor bug in it, I mean...
Code:
// Check extension
strExtension = FileInformation.cFileName;
strExtension = strExtension.substr(strExtension.find(".") + 1);
like, it doesn't catch files like "this.is.my.file.txt" and I guess the solution was to use reverse iterator or _splitpath(...).
I just came through this thread and found that the FAQ is not updated, so just mentioned it, nothing personal
-
December 23rd, 2003, 10:55 AM
#5
Originally posted by Ejaz
Although the code in the link that u mention is quite perfect, but I saw another thread, which mentioned a minor bug in it...
Well...I would not consider this as a bug since I am still of the opinion that filenames like "this.is.my.file.txt" are invalid.
Anyway, this can be solved by using the 'rfind()' function instead of 'find()'. Since I do not want to start a discussion about whether these names are invalid or not, I simply changed the appropriate FAQs...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|