Listing files from a given directory

I tried listing files using the code given in "http://forum.codecall.net/topic/57996-list-files-in-a-directory-for-c/" the program listed all the files present in the current dirctory but if i change the drive and the directory to such as "C:\Users\Baaoo\Downloads\direct.h function"
the program does not list files name, any suggestion.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#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;
}
Are you remembering that '\' is an escape character and needs to be doubled up on?

Are you trying to use a *nix command in a Windows environment? Stop that. Here is a link to how you do it in Windows: http://www.cplusplus.com/forum/general/107091/
Last edited on
Topic archived. No new replies allowed.