Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- # Open and read list.txt, file generated with command "ls -AmUFR /your/path > list.txt"
- list_file = open("list.txt")
- list_file_content = list_file.read()
- # Split the content per-folder (they're separed by "\n\n")
- all_folders = list_file_content.split("\n\n")
- # Create a list containing a list for each folder, first element being folder name
- all_folders_files = []
- for folder in all_folders:
- # Folder name and its files are separed by ":\n"
- folder_split = folder.split(":")
- # Add the folder name to a new list as first element
- this_folder = list()
- this_folder.append(folder_split[0])
- folder_files = folder_split[1].split(",")
- for file_name in folder_files:
- # Remove potential unneeded newline in file name
- file_name = file_name.replace("\n", "")
- # Add to the list
- this_folder.append(file_name)
- # Finally, add this folder's content to the main list
- all_folders_files.append(this_folder)
- # Output the list to a file
- output_file = file("output.txt", "w")
- print >> output_file, all_folders_files
Add Comment
Please, Sign In to add comment