Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Some help with moving files
#1
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.
Reply
#2
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()])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Moving specific files then unzipping/decompressing christophereccles 2 2,325 Apr-24-2021, 04:25 AM
Last Post: ndc85430
  Moving files to Folders giddyhead 13 9,005 Mar-07-2021, 02:50 AM
Last Post: giddyhead
  Moving Files From Subdirectories To Another Directory Harshil 5 3,907 Oct-06-2020, 10:52 AM
Last Post: ndc85430
  Moving Files Evil_Patrick 4 2,429 Oct-02-2019, 02:56 AM
Last Post: Evil_Patrick

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020