"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Fun File Mover Script: From Desktop to Screenshots Folder

Fun File Mover Script: From Desktop to Screenshots Folder

Published on 2024-11-08
Browse:203

Fun File Mover Script: From Desktop to Screenshots Folder

Ever felt overwhelmed by the clutter on your desktop? ?️ If you're like me, your desktop might be a treasure trove of random files. One common culprit? Screenshots! ? They pile up faster than you can say "file management."

So, I decided to tackle this problem with a fun little script. Here’s how you can move all those screenshots (or any specific file type) from your desktop to a designated folder, all while keeping things neat and organized. ?

What You’ll Need
Python installed on your computer.
pathlib library (comes with Python, so no extra installations required!).

The Script
Here's the script that does all the heavy lifting:

import pathlib

Set the paths
desktop = pathlib.Path('/Users/91763/Desktop')
new_path = pathlib.Path('/Users/91763/Desktop/Screenshots')

Create the destination folder if it doesn't exist
new_path.mkdir(exist_ok=True)

Move all PNG files from the desktop to the new folder
for filepath in desktop.iterdir():
if filepath.suffix == '.png':
new_filepath = new_path.joinpath(filepath.name)
filepath.replace(new_filepath)

Breaking It Down

Setting Paths: We start by defining the paths for our desktop and the new folder where we want to move our screenshots.

Creating the Folder: new_path.mkdir(exist_ok=True) ensures that our new folder exists. If it doesn’t, it creates one for us.

Finding and Moving Files: We loop through each file on the desktop using desktop.iterdir(). If the file is a PNG (you can change this to any extension you like!), it gets moved to the new folder.

Why It’s Cool

Automation: No more manually sorting through files.

Organization: Keeps your desktop clean and your screenshots neatly tucked away.

Simplicity: The script is straightforward and easy to adapt for other file types or destinations.

Try this out and watch your desktop transform from a chaotic mess into a model of organization! ? If you have any questions or suggestions, drop them below. Happy coding! ?

Release Statement This article is reproduced at: https://dev.to/debojit_choudhury_a889561/fun-file-mover-script-from-desktop-to-screenshots-folder-b34?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3