
Automatizar carpetas en python
Publicado por Rodrigo (1 intervención) el 07/07/2021 21:01:33
Hola no me funciona el codigo si alguin me podria ayudar
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
ruta_descargas = 'C:\\Users\\rovel\\Downloads'
temporizador = 30
ext_vid = ['.mov', '.mp4', '.avi', '.mkv', '.mkv', '.flv', '.wmv']
ext_aud = ['.mp3', '.wma', '.wav', '.flac']
ext_img = ['.jpg', '.png', 'jpeg', '.gif', '.tiff', '.psd', '.bmp', '.ico', '.svg']
ext_doc = ['.txt', '.doc', '.docx', 'pptx', '.odf', '.docm', '.pdf']
ext_com = ['.zip', '.rar', '.rar5', '.7z', '.ace', '.gz']
ext_ins = ['.exe', '.msi']
def motor(archivo, ext):
for i in ext_doc:
if ext == i:
shutil.move(ruta_descargas + archivo + i, ruta_descargas + 'Documentos')
for i in ext_aud:
if ext == i:
shutil.move(ruta_descargas + archivo + i, ruta_descargas + 'Audio')
for i in ext_img:
if ext == i:
shutil.move(ruta_descargas + archivo + i, ruta_descargas + 'Imagenes')
for i in ext_doc:
if ext == i:
shutil.move(ruta_descargas + archivo + i, ruta_descargas + 'Documentos')
for i in ext_ins:
if ext == i:
shutil.move(ruta_descargas + archivo + i, ruta_descargas + 'Instaladores')
for i in ext_com:
if ext == i:
shutil.move(ruta_descargas + archivo + i, ruta_descargas + 'Comprimidos')
if ext != '':
shutil.move(ruta_descargas + archivo + i, ruta_descargas + 'Otros')
def verificar():
for archivo in os.listdir(ruta_descargas):
nombre_archivo, ext = os.path.splitext(archivo)
motor(nombre_archivo, ext)
while(True):
try:
time.sleep(temporizador)
for _ in range(len(os.listdir(ruta_descargas))):
try:
verificar()
except:
pass
except KeyboardInterrupt:
break
Valora esta pregunta


0