Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* list contents of a directory */
- #include <iostream>
- #include "C:\\Users\\Kimossab\\Documents\\Visual Studio 2015\\Projects\\test\\test\\dirent.h"
- using namespace std;
- void main(int argc, char *argv[])
- {
- /* check command line arguments */
- if (argc <= 2)
- {
- fprintf(stderr, "usage: printdir directory\n");
- return;
- }
- /* print contents of directories listed in command line */
- /* open directory stream */
- DIR *dir = opendir(argv[1]);
- DIR *dir2;
- struct dirent *ent;
- struct dirent *ent2;
- string aux;
- if (dir != NULL)
- {
- /* print all the files and directories within directory */
- while ((ent = readdir(dir)) != NULL)
- {
- switch (ent->d_type)
- {
- case DT_DIR:
- string ax = argv[1];
- aux = ax + "\\" + ent->d_name;
- dir2 = opendir(aux.c_str());
- if (dir2 != NULL)
- {
- /* print all the files and directories within directory */
- while ((ent2 = readdir(dir2)) != NULL)
- {
- switch (ent->d_type)
- {
- case DT_REG:
- cout << ent->d_name;
- }
- }
- cout << ";";
- }
- break;
- }
- }
- closedir(dir);
- }
- else
- /* could not open directory */
- perror("");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement