How to get ALL filenames in directory output?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <dirent.h>

int main(void)
{
    struct dirent *de;  // Pointer for directory entry

    // opendir() returns a pointer of DIR type.
    DIR *dr = opendir("d:/lemon");

    if (dr == NULL)  // opendir returns NULL if couldn't open directory
    {
        printf("Could not open current directory" );
        return 0;
    }

    // Refer http://pubs.opengroup.org/onlinepubs/7990989775/xsh/readdir.html
    // for readdir()
    while ((de = readdir(dr)) != NULL)
            printf("%s\n", de->d_name);

    closedir(dr);
    return 0;
}
This code outputs only 296 filenames of 1501. Can I get them all? I also tried CMD and it also outputs only 296 filenames
Last edited on
Try

system("dir >File_directory.txt");// Winodws only

The contents of the directory are dumped into a text file named: "File_directory.txt"

If you use Lunix then you must another command. ("ls"?)
Yeah, thanks, it works well, it's probably limitation of CMD interface
Topic archived. No new replies allowed.