-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_mover.py
67 lines (50 loc) · 2.42 KB
/
file_mover.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import shutil
import random
import string
dummy_folders = ["text", "executables", "images", "pdfs", "videos", ]
# extensions = [".txt", ".exe", ".jpg", ".pdf", ".mp4"]
extensions = {"txt": ".txt", "exe": ".exe", "jpg": ".jpg", "pdf": ".pdf", "mp4": ".mp4"}
desktop_path = os.path.join(os.path.expanduser('~'), 'Desktop')
all_files_directory = os.path.join(desktop_path, "allfiles")
def make_all_files_directory():
os.mkdir(all_files_directory)
def dummy_folder_maker():
for i in range(len(dummy_folders)):
os.mkdir(os.path.join(desktop_path, dummy_folders[i]))
def delete_dummy_folders():
for i in range(len(dummy_folders)):
os.rmdir(os.path.join(desktop_path, dummy_folders[i]))
def delete_all_files():
for dummy_files in os.listdir(all_files_directory):
os.remove(os.path.join(all_files_directory, dummy_files))
def create_random_files():
for i in range(10):
with open(
os.path.join(all_files_directory,
f"{''.join(random.choices(string.ascii_letters, k=10))}{random.choice(list(extensions.values()))}"),
"w") as f:
pass
def move_files():
for files in os.listdir(all_files_directory):
if files.endswith(extensions.get("txt")):
shutil.move(os.path.join(all_files_directory, files),
os.path.join(desktop_path, dummy_folders.__getitem__(0), files))
elif files.endswith(extensions.get("exe")):
shutil.move(os.path.join(all_files_directory, files),
os.path.join(desktop_path, dummy_folders.__getitem__(1), files))
elif files.endswith(extensions.get("jpg")):
shutil.move(os.path.join(all_files_directory, files),
os.path.join(desktop_path, dummy_folders.__getitem__(2), files))
elif files.endswith(extensions.get("pdf")):
shutil.move(os.path.join(all_files_directory, files),
os.path.join(desktop_path, dummy_folders.__getitem__(3), files))
elif files.endswith(extensions.get("mp4")):
shutil.move(os.path.join(all_files_directory, files),
os.path.join(desktop_path, dummy_folders.__getitem__(-1), files))
# make_all_files_directory()
# dummy_folder_maker()
# create_random_files()
# move_files()
# delete_dummy_folders()
# delete_all_files()