-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercicio1.py
More file actions
31 lines (23 loc) · 774 Bytes
/
exercicio1.py
File metadata and controls
31 lines (23 loc) · 774 Bytes
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
import os
def organize_files():
types = ['wmv', 'csv','jpg', 'pdf', 'png']
# 1 - Diretório raiz
base_path = os.path.expanduser('~')
# 2 - Navega no diretório Downloads
path = os.path.join(base_path, 'downloads-teste')
cwd = os.chdir(path)
# 3 - Lista arquivos do diretório
list_files = os.listdir(cwd)
print(list_files)
# 4 - Organizando arquivos
for t in types:
if t not in os.listdir():
os.mkdir(t)
for file in list_files:
for t in types:
if '.' + t in file:
old_path = os.path.join(path, file)
new_path = os.path.join(path, t, file)
os.replace(old_path, new_path)
if __name__ == "__main__":
organize_files()