Create a python script that sorts files on the desktop into separate folders based on…
- User
Create a python script that sorts files on the desktop into separate folders based on their file type. The script should prompt the user for the source and destination paths, and then guide the user through the process of setting up the file types dictionary and running the sorting code.
- Assistant
Sure, here's an example Python script that sorts files on the desktop into separate folders based on their file type:
import os import shutil # Prompt the user for the source and destination paths source_path = input("Enter the source path: ") destination_path = input("Enter the destination path: ") # Define a dictionary of file types and their corresponding folder names file_types = { ".txt": "Text Files", ".docx": "Word Documents", ".jpg": "JPEG Images", ".pdf": "PDF Documents" } # Create the destination folders for folder_name in file_types.values(): folder_path = os.path.join(destination_path, folder_name) os.makedirs(folder_path, exist_ok=True) # Loop through the files in the source directory for file_name in os.listdir(source_path): file_path = os.path.join(source_path, file_name) if os.path.isfile(file_path): # Get the file extension and corresponding folder name file_extension = os.path.splitext(file_name)[1].lower() if file_extension in file_types: folder_name = file_types[file_extension] # Move the file to the corresponding destination folder destination_folder = os.path.join(destination_path, folder_name) shutil.move(file_path, destination_folder) print(f"Moved {file_name} to {destination_folder}") - User
How to customize it to any file types I want? Can you provide me the code for that too since I am not very good at using python. Also just to be sure, it wont mess up the sorting process right? I don't want two different file types in the same folder
- Assistant
To customize it to sort any file types you want, you can modify the
file_typesdictionary to include additional entries:file_types = { ".txt": "Text Files", ".docx": "Word Documents", ".jpg": "JPEG Images", ".pdf": "PDF Documents", ".rtf": "Rich Text Documents", ".png": "PNG Images" }Add them with the syntax of
".extension": "Folder Name",and remember to put a comma at the end of each line except for the bottom line.The Python script itself could be modified to import the different file extensions and directory names from a file, if desired. Would you like me to create this for you?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)