Guest User

Untitled

a guest
Dec 13th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys
  3.  
  4. # Open and read list.txt, file generated with command "ls -AmUFR /your/path > list.txt"
  5. list_file = open("list.txt")
  6. list_file_content = list_file.read()
  7.  
  8. # Split the content per-folder (they're separed by "\n\n")
  9. all_folders = list_file_content.split("\n\n")
  10.  
  11. # Create a list containing a list for each folder, first element being folder name
  12. all_folders_files = []
  13.  
  14. for folder in all_folders:
  15. # Folder name and its files are separed by ":\n"
  16. folder_split = folder.split(":")
  17.  
  18. # Add the folder name to a new list as first element
  19. this_folder = list()
  20. this_folder.append(folder_split[0])
  21.  
  22. folder_files = folder_split[1].split(",")
  23.  
  24. for file_name in folder_files:
  25. # Remove potential unneeded newline in file name
  26. file_name = file_name.replace("\n", "")
  27.  
  28. # Add to the list
  29. this_folder.append(file_name)
  30.  
  31. # Finally, add this folder's content to the main list
  32. all_folders_files.append(this_folder)
  33.  
  34. # Output the list to a file
  35. output_file = file("output.txt", "w")
  36.  
  37. print >> output_file, all_folders_files
Add Comment
Please, Sign In to add comment