forked from techyminati/python_codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_organiser.py
62 lines (58 loc) · 1.82 KB
/
file_organiser.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
#!/usr/bin/python
'''
Files Organiser
Author: Shanmukha Vishnu
gitub: @iam-shanmukha
twitter: @iam_shanmukha
'''
import os
import shutil
doc_extensions=[".txt",".docx",".doc",".xls",".xls",".csv"]
compress_ext =[".zip",".rar",".zst",".gz",".xz"]
vids_ext=[".mp4",".avi",".mkv"]
pic_ext=[".png",".jpg",".jpeg"]
softwares_ext = [".AppImage",".deb"]
audio_ext=[".mp3",".ogg",".wav",".m4a"]
#list present working directory files and folders
#ls = files+folders
ls=os.listdir()
def create_dirs():
directories = ["Pdfs", "Pictures", "Videos", "compressed_Files", "Documents", "Py_files", "softwares", "Audios"]
for directory in directories:
if directory in ls:
print(f"{directory} directory exists...skipping ")
else:
print(f"Creating {directory} Directory")
os.mkdir(directory)
create_dirs()
for file in ls:
try:
if file.endswith(".pdf"):
shutil.move(file, "Pdfs")
print(f"{file} files moved successfully")
elif file.endswith(tuple(pic_ext)):
shutil.move(file, "Pictures")
print(f"{file} files moved successfully")
elif file.endswith(tuple(vids_ext)):
shutil.move(file, "Videos")
print(f"{file} files moved successfully")
elif file.endswith(tuple(compress_ext)):
shutil.move(file, "compressed_Files")
print(f"{file} files moved successfully")
elif file.endswith(tuple(doc_extensions)):
shutil.move(file, "compressed_Files")
print(f"{file} files moved successfully")
elif file.endswith(tuple(softwares_ext)):
shutil.move(file, "softwares")
print(f"{file} files moved successfully")
elif file.endswith(tuple(audio_ext)):
shutil.move(file, "Audios")
print(f"{file} files moved successfully")
elif file.endswith(".py"):
if file == "organiser.py":
continue
shutil.move(file, "Py_files")
print(f"{file} files moved successfully")
except shutil.Error as E:
print("ERROR",E)
continue