-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (33 loc) · 1.42 KB
/
Copy pathmain.py
File metadata and controls
42 lines (33 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
from pathlib import WindowsPath
import FileWatcher
source_folder = WindowsPath.cwd()
FileWatcher.start_watching(source_folder)
file_types = {"documents": [".pdf", ".txt", ".docx"], "pictures": [".jpg", ".jpeg", ".png", ".gif", ".bmp"]}
# define move_pictures inherits source_folder as src
def move_pictures(src=source_folder):
destination_folder = src.joinpath("pictures")
# okay if fir exists
os.makedirs(destination_folder, exist_ok=True)
for file in os.listdir(source_folder):
if file.endswith(str(file_types.get("pictures"))):
source_path = os.path.join(source_folder, file)
destination_path = os.path.join(destination_folder, file)
os.rename(source_path, destination_path)
print(f"moved {file} to {destination_path}")
else:
continue
def move_documents(src=source_folder):
destination_folder = src.joinpath("documents")
if not os.path.exists(destination_folder):
os.makedirs(destination_folder, exist_ok=True)
for file in os.listdir(source_folder):
if file.endswith(str(file_types.get("documents"))):
source_path = os.path.join(source_folder, file)
destination_path = os.path.join(destination_folder, file)
os.rename(source_path, destination_path)
print(f"moved {file} to {destination_path}")
else:
continue
move_documents()
move_pictures()