Python Forum

Full Version: Some help with moving files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I am really new to python and scripting as a hole, and only know a few really simple scripts here and there.

I thought as a fun thing to do is when you launch an .EXE and would search your desktop and if it finds anything like a folder, it would put it in to a folder named "Folders". Then find anything with an .EXE, excluding itself, and puts it into a folder named "ExecuteFolder". Then pictures such as a PNG and JPG would be moved to the "Picture" folder and music in "Music" and videos in to "videos", and then finds anything else and puts it in to a folder called "Misc".

I'm not asking for the hole script for this sense i'm trying to challenge myself and watch online videos on the matter, but like tips for what to use in such.
generally, executable files are kept in a bin directory
pictures would go in a directory named images.
This is a pseudo standard, which can be deviated from, but it is suggested naming.

look at pathlib: https://docs.python.org/3/library/pathlib.html
it maked file and directory navigation a snap.
for example, to create a refrence to your home directory, the code would be:
from pathlib import Path

home = Path('.')
Next to create your bin directory under home you would use:
bin = home / 'bin'
bin.mkdir(exist_ok=True)
this will create the directory if not there, and only if not there.

Now if you wanted to get a list of all files in bin:
print([filename for filename in bin.iterdir() if filename.is_file()])