Skip to content

Instantly share code, notes, and snippets.

@abrarShariar
Last active December 24, 2015 12:38
Show Gist options
  • Save abrarShariar/d752cd35c6b23f0177b9 to your computer and use it in GitHub Desktop.
Save abrarShariar/d752cd35c6b23f0177b9 to your computer and use it in GitHub Desktop.
View list of all directories and files in the mentioned location
#include<iostream>
#include<dirent.h>
#include<cstdio>
using namespace std;
//Shows all the subdirectories and files in mentioned location
int main(){
const char *location="E:\\2nd_semester\\C++\\C++Phone\\Code\\music";
DIR *dir;
struct dirent *ent;
if ((dir = opendir (location)) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) {
printf ("%s\n", ent->d_name);
}
closedir (dir);
} else {
/* could not open directory */
perror ("");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment