-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove.py
More file actions
48 lines (34 loc) · 1.01 KB
/
move.py
File metadata and controls
48 lines (34 loc) · 1.01 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
43
44
45
46
47
48
from os import path
import shutil
import os
files = []
errors = []
def file_exist(location):
ext = path.splitext(location)[1]
if ext == ".png" or ext == ".jpg" or ext == ".mp4" or ext == ".gif":
files.append(location)
def move_file(file_name, folder_name):
try:
create_folder(folder_name)
shutil.move(move_path + '\\' + file_name, move_path +
'\\' + folder_name + '\\' + file_name)
os.chdir(move_path)
except Exception as _:
errors.append(file_name)
os.chdir(move_path)
print("Error", file_name)
def create_folder(file_name):
dir_name = path.join(path.abspath('')) + '\\' + file_name
if not os.path.exists(dir_name):
os.mkdir(dir_name)
os.chdir(dir_name)
def main():
move_path = path.abspath('.')
tmp_files = os.listdir(move_path)
for my_file in tmp_files:
file_exist(my_file)
return move_path
move_path = main()
print(len(files))
for nfile in files:
move_file(nfile, 'Pictures')