Guest User

Untitled

a guest
Jan 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. int list_file(string path)
  2. {
  3. DIR *dir;
  4. struct dirent *ent;
  5. char *c_style_path;
  6. c_style_path = new char[path.length()];
  7. c_style_path = (char *)path.c_str();
  8. dir = opendir (c_style_path);
  9. if (dir != NULL) {
  10.  
  11. /* print all the files and directories within directory */
  12. while ((ent = readdir (dir)) != NULL) {
  13. if(ent->d_type == DT_DIR && (strcmp(ent->d_name,".")!=0) && (strcmp(ent->d_name,"..")!=0))
  14. {
  15. string tmp = path + "\" + ent->d_name;
  16. list_file(tmp);
  17. }
  18. else
  19. {
  20. cout<<ent->d_name<<endl;
  21. }
  22. }
  23. closedir (dir);
  24. } else {
  25. /* could not open directory */
  26. perror ("");
  27. return EXIT_FAILURE;
  28. }
  29. delete [] c_style_path;
  30. return 0;
  31. }
  32.  
  33. c_style_path = (char *)path.c_str();
  34. //...
  35. delete[] c_style_path;
  36.  
  37. dir = opendir (path.c_str());
Add Comment
Please, Sign In to add comment