Hi, how do you read all of the file names that are in a folder? I'll also want to save all the names as a list in a text document, but I already know how to create files I just need to know how to read all of their names.
Hi, how do you read all of the file names that are in a folder? I'll also want to save all the names as a list in a text document, but I already know how to create files I just need to know how to read all of their names.
For Windows you would use the FindNextFile() function.
FindNextFile() MSDN
Googling around shows that you could do something like this via system():
For Windows/DOS:
I believe for *nix systems, the following should work:Code:system("dir directory >> files.txt ");
directory would have to be replaced with whatever directory you want to search through. After executing this, the output of the command (including the file list) would be placed inside a file named files.txt.Code:system("ls directory >> files.txt ");
Otherwise, I believe you would have to find the O/S specific system calls to get the information you want, such as what Sentral posted.
Does boost have any portable libary for that kind of purpuse?
You can also read our FAQ entry about reading all the files within a directory.