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
Certainly! Here's a Python script that should meet your requirements. This script utilizes the os and shutil modules to scan, identify, and move files based on their extensions. Before running the script, make sure to adjust the folder_map dictionary to match the folder names on your computer.
import os import shutil # Set the paths for your desktop and destination folders desktop_path = os.path.join(os.path.expanduser("~"), "Desktop") documents_path = os.path.join(os.path.expanduser("~"), "Documents") pictures_path = os.path.join(os.path.expanduser("~"), "Pictures") videos_path = os.path.join(os.path.expanduser("~"), "Videos") # Define the mapping between file extensions and destination folders folder_map = { ".doc": documents_path, ".docx": documents_path, ".xls": documents_path, ".xlsx": documents_path, ".pdf": documents_path, ".txt": documents_path, ".jpg": pictures_path, ".jpeg": pictures_path, ".png": pictures_path, ".gif": pictures_path, ".bmp": pictures_path, ".mp4": videos_path, ".avi": videos_path, ".mkv": videos_path, ".mov": videos_path, ".wmv": videos_path, } # Scan the desktop and move files to the appropriate folders for file in os.listdir(desktop_path): file_path = os.path.join(desktop_path, file) if os.path.isfile(file_path): file_ext = os.path.splitext(file)[1] if file_ext in folder_map: dest_folder = folder_map[file_ext] shutil.move(file_path, dest_folder) print(f"Moved '{file}' to '{dest_folder}'") else: print(f"Skipping '{file}': No matching folder for '{file_ext}'")
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 →