Created
October 29, 2022 23:01
-
-
Save nosrednawall/9512508b4d36707e4faf01b8dd7e1731 to your computer and use it in GitHub Desktop.
move todos os arquivps de um tipo, das subpastas para a pasta mae
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
import shutil | |
import glob | |
def mover_arquivo_subpastas(): | |
path = r"/home/anderson/Vídeos/Mob Pyscho 100 (2016)/mob_s3/" # caminho da pasta | |
files = glob.glob(path + '/**/*.mkv', recursive=True) # gera uma lista dos arquivos no tipo especificado, mkv, recusivamente | |
for file in files: | |
padrao = re.compile(r"[^\\/]+?(?=$)") # regex para pegar o nome do arquivo mais a extensão, ignorando todo o path | |
possui_nome_arquivo = padrao.search(file) | |
if possui_nome_arquivo: | |
nome_arquivo = possui_nome_arquivo.group() | |
source = file | |
destination = f"{path}{nome_arquivo}" | |
shutil.move(source, destination) # realiza a ação de mover o arquivo | |
mover_arquivo_subpastas() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment