I need a Python script that can help me organize my Windows computer by sorting files by…
- User
I need a Python script that can help me organize my Windows computer by sorting files by type from my desktop and putting them into the correct folder. The script should be able to scan my desktop and identify the type of each file based on its extension (e.g., .docx, .jpg, .pdf). Then, it should find the correct folder for each file type (e.g., 'Documents', 'Pictures', 'Videos') and move the corresponding files to the appropriate folder. Can you generate a script that meets these requirements?
- Assistant
Yes, I can help you with that. Here's a Python script that will do the job. Before running the script, make sure you have Python installed on your computer. This script assumes that you have folders named 'Documents', 'Pictures', and 'Videos' on your desktop. If you don't have these folders, you can either create them manually or modify the script to create them automatically.
import os import shutil # Set the path to your desktop desktop_path = os.path.join(os.path.expanduser('~'), 'Desktop') # Define the folders for each file type folders = { 'Documents': ['.doc', '.docx', '.txt', '.pdf', '.xls', '.xlsx', '.ppt', '.pptx'], 'Pictures': ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.ico', '.tiff', '.tif'], 'Videos': ['.mp4', '.mkv', '.flv', '.avi', '.mov', '.wmv'], } # Iterate through each file on the desktop for file in os.listdir(desktop_path): file_path = os.path.join(desktop_path, file) # Skip folders if os.path.isdir(file_path): continue # Get the file extension file_ext = os.path.splitext(file)[1] # Iterate through the folders dictionary to find the appropriate folder for the file for folder, extensions in folders.items(): if file_ext.lower() in extensions: # Set the destination path for the file destination = os.path.join(desktop_path, folder) # Move the file to the appropriate folder shutil.move(file_path, os.path.join(destination, file)) print(f'Moved {file} to {folder}') break
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 →