-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoMove.py
136 lines (117 loc) · 4.52 KB
/
AutoMove.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
'''
Solely developed by PRIYANSHU KUMAR
An almost basic Python script to Arrange files based on extensions
Permitted for own usage(Under MIT License)
'''
# TODO:Save the moved file data into a database and ignore those files (or check only current dir.)
# TODO:Make only those folders which are needed as per the Extension requirement
# TODO:Make it to ignore itself and not get moved somewhere else
# TODO:Convert the .py file to .exe to run anywhere just by double click
# Importing needed modules
import time
import os
import sys
import shutil
# Saving the path of Current Working Directory
rootdir = os.getcwd()
# Function to Create different directories to store specific files
def create_the_directories():
i = 0
j = 0
k = 0
l = 0
m = 0
n = 0
for root, dirs, files in os.walk(rootdir):
for dir in dirs:
print(dir)
if dir.lower() == "music" or dir.lower() == "musics":
i += 1
if dir.lower() == "video" or dir.lower() == "videos":
j += 1
if dir.lower() == "book" or dir.lower() == "books":
k += 1
if dir.lower() == "other" or dir.lower() == "others":
l += 1
if dir.lower() == "program" or dir.lower() == "programs":
m += 1
if dir.lower() == "image" or dir.lower() == "images":
n += 1
# Create the directory if it is not already present
if i == 0:
os.mkdir(rootdir + "\\Music")
if j == 0:
os.mkdir(rootdir + "\\Video")
if k == 0:
os.mkdir(rootdir + "\\Books")
if l == 0:
os.mkdir(rootdir + "\\Others")
if m == 0:
os.mkdir(rootdir + "\\Programs")
if n == 0:
os.mkdir(rootdir + "\\Images")
# Calling the Function to start creating directories
create_the_directories()
# Function to move the file from source to destination
def move_the_file(source, destination):
#os.rename(source, destination)
shutil.move(source, destination)
#os.replace(source, destination)
# Function to Check the extension of file and move it to its specific directory
def checking_files():
for root, dirs, files in os.walk(rootdir):
ind = 0
# Checking the extensions
for file in files:
ind += 1
if "mp4" in file or "MP4" in file \
or "wmv" in file or "WMV" in file \
or "avi" in file or "AVI" in file:
source = root + "\\" + file
print(source)
destination = rootdir+"\\Video\\" + file
print(destination)
move_the_file(source, destination)
elif "jpg" in file or "JPG" in file \
or "jpeg" in file or "JPEG" in file \
or "png" in file or "PNG" in file \
or "bmp" in file or "BMP" in file:
source = root + "\\" + file
print(source)
destination = rootdir+"\\Images\\" + file
print(destination)
move_the_file(source, destination)
elif "mp3" in file or "MP3" in file \
or "wav" in file or "WAV" in file \
or "aif" in file or "AIF" in file:
source = root + "\\" + file
print(source)
destination = rootdir+"\\Music\\" + file
print(destination)
move_the_file(source, destination)
elif "pdf" in file or "PDF" in file \
or "doc" in file or "DOC" in file \
or "txt" in file or "TXT" in file:
source = root + "\\" + file
print(source)
destination = rootdir+"\\Books\\" + file
print(destination)
move_the_file(source, destination)
elif "exe" in file or "EXE" in file \
or "app" in file or "APP" in file \
or "vb" in file or "VB" in file:
source = root + "\\" + file
print(source)
destination = rootdir+"\\Programs\\" + file
print(destination)
move_the_file(source, destination)
# else:
# source = root + "\\" + file
# print(source)
# destination = rootdir+"\\Others\\" + file
# print(destination)
# move_the_file(source, destination)
# Calling the function to check and move the files
while True:
checking_files()
time.sleep(1)