How can I count the number of files in a directory using C on linux platform.
Browse to the folder containing the files you want to count. Highlight one of the files in that folder and press the keyboard shortcut Ctrl + A to highlight all files and folders in that folder. In the Explorer status bar, you'll see how many files and folders are highlighted, as shown in the picture below.
On the contextual menu, select Properties. Alternatively, select the folder and press the Alt + Enter keys on your keyboard. When the Properties window opens, Windows 10 automatically starts counting the files and folders inside the selected directory.
No guarantee that this code compiles, and it's really only compatible with Linux and the BSDs:
#include <dirent.h> ... int file_count = 0; DIR * dirp; struct dirent * entry; dirp = opendir("path"); /* There should be error handling after this */ while ((entry = readdir(dirp)) != NULL) { if (entry->d_type == DT_REG) { /* If the entry is a regular file */ file_count++; } } closedir(dirp);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With