Write a program to list files in the directory.
C Program
#include <stdio.h>#include <dirent.h>int main(){DIR *d;struct dirent *dir;char filechar[1000];printf("Enter file directory path: ");scanf("%s", filechar);d = opendir(filechar);if (d){while ((dir = readdir(d)) != NULL){printf("%s\n", dir->d_name);}closedir(d);}return 0;}
Input:
Enter file directory path: C:\Users
Output:
. .. .849C9593-D756-4E56-8D6E-42412F2A707B 1706073_6CS123.pdf Attachments Book.xlsx Desktop desktop.ini Documents Getting started with OneDrive.pdf Personal Vault.lnk Pictures Presentation.pptx
No comments:
Post a Comment