GERARDO LABANCA

Generation

generate functionSat, 25 Mar 2023

un progrma para copiar archivos de una carpeta que contengan nombres de un rango de fechas pero que contengan hora como este ejemplo de archivo A01_20210707000041.mp4

import os import shutil import time cwd = os.getcwd() extensio_type = 'mp4' max_date = time.strftime('%Y%m%d') min_date = time.strftime('20210707') for file in os.listdir(cwd): if os.path.isfile(file) and file.endswith(f'.{extensio_type}'): file_name = file.split('.')[0] date = file_name[3:11] if int(date) >= int(min_date) and int(date) <= int(max_date): new_file = file_name + '.' + extensio_type shutil.copy(file, new_file) print(f'Copied: {file} to {new_file}')

Questions about programming?Chat with your personal AI assistant