Hi!
I need a way to list all files in a directory and I would prefer if there were a common way to do it in both Linux and Windows? If not then give me the two different ways and I'll just make it work with both Linux and Windows using the preprocessor defines.
Links for further information is also appreciated.
Thanks on beforehand.
4 replies to this topic
#1
Posted 01 August 2010 - 04:14 PM
My Code Blog - My Github - Ascension Project - Madness Script Project - Simple-Garbage-Collector Project
There is bound to be something useful somewhere.
There is bound to be something useful somewhere.
|
|
|
#2
Posted 01 August 2010 - 04:47 PM
#include <iostream>
#include <dirent.h>
using namespace std;
int main() {
DIR* dir;
dirent* pdir;
dir = opendir("."); // open current directory
while (pdir = readdir(dir)) {
cout << pdir->d_name << endl;
}
closedir(dir);
return 0;
}
Some further reading: cplusplus.com linuxquestions.org wikipedia.org
I think it works on *nix as well.
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#3
Posted 01 August 2010 - 06:23 PM
I found a Windows clone of the dirent.h file thanks to you on the Wikipedia page you wrote.
Thanks & +rep!
Thanks & +rep!
My Code Blog - My Github - Ascension Project - Madness Script Project - Simple-Garbage-Collector Project
There is bound to be something useful somewhere.
There is bound to be something useful somewhere.
#4
Posted 01 August 2010 - 08:25 PM
I may be a little late, but I have another resource that you may find useful:
C Directory Tutorial [intma.in]
C Directory Tutorial [intma.in]
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)
Download the new operating system programming kit! (some assembly required)
#5
Posted 01 August 2010 - 08:57 PM
For MS-Windows see the FindFirstFile() and FindNextFile() win32 api functions. I think there boost also has functions that are os independent.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









