summaryrefslogtreecommitdiff
path: root/ls.c
blob: 876e60e146579db988625e20abd0b8eda7f08fec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * =====================================================================================
 *
 *       Filename:  ls.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  02/18/2025 15:39:55
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#include <stdlib.h>
#include <stdio.h>
#include <dirent.h>


int main(){

    char *path = "folder";
    struct dirent *entry;
    DIR *dP = opendir(path);

    // check if the directory got opened successfully
    if (dP == NULL) {
        perror("opendir");
        return 1;
    }

    // print the folder|directory name
    while ((entry = readdir(dP)) != NULL) {
        char *temporary_variable = entry->d_name;
        printf("%s\n", entry->d_name);
    }
    closedir(dP);

}