-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrganizerFiles.py
57 lines (48 loc) · 1.69 KB
/
OrganizerFiles.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
import os
import shutil
import time
def organizerFiles():
downloadDir = r"C:\Users\YourUser\Downloads"
# Dictionary mapping file extensions to folders
fileTypes = {
'jpg': 'images',
'png': 'images',
'gif': 'images',
'doc': 'documents',
'docx': 'documents',
'pdf': 'documents',
'xlsx': 'documents',
'txt': 'documents',
'mp4': 'videos',
'avi': 'videos',
'mkv': 'videos',
'exe': 'programs',
'msi': 'programs',
}
totalFiles = len(os.listdir(downloadDir))
movedFiles = 0
for file in os.listdir(downloadDir):
routeFile = os.path.join(downloadDir, file)
if os.path.isfile(routeFile):
extension = file.split(".")[-1].lower()
if extension in fileTypes:
destinationDir = os.path.join(downloadDir, fileTypes[extension])
if not os.path.exists(destinationDir):
os.makedirs(destinationDir)
destinationRoute = os.path.join(destinationDir, file)
shutil.move(routeFile, destinationRoute)
print(f"Archivo {file} movido a {destinationRoute}")
movedFiles += 1
progress = movedFiles / totalFiles
progressBar(totalFiles, movedFiles, progress)
time.sleep(0.5)
progressBar(totalFiles, movedFiles, 1)
print("\n¡Tarea completada!")
def progressBar(total, current, progress):
barLength = 50
filledLength = int(round(barLength * progress))
bar = '#' * filledLength + '-' * (barLength - filledLength)
percentage = round(progress * 100, 2)
print(f'[{bar}] {percentage}% complete ', end='\r')
# RUN
organizerFiles()