forked from luizomf/cursopython2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaula173.py
26 lines (22 loc) · 853 Bytes
/
aula173.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
# os + shutil - Copiando arquivos com Python
# Vamos copiar arquivos de uma pasta para outra.
# Copiar -> shutil.copy
import os
import shutil
HOME = os.path.expanduser('~')
DESKTOP = os.path.join(HOME, 'Desktop')
PASTA_ORIGINAL = os.path.join(DESKTOP, 'EXEMPLO')
NOVA_PASTA = os.path.join(DESKTOP, 'NOVA_PASTA')
os.makedirs(NOVA_PASTA, exist_ok=True)
for root, dirs, files in os.walk(PASTA_ORIGINAL):
for dir_ in dirs:
caminnho_novo_diretorio = os.path.join(
root.replace(PASTA_ORIGINAL, NOVA_PASTA), dir_
)
os.makedirs(caminnho_novo_diretorio, exist_ok=True)
for file in files:
caminho_arquivo = os.path.join(root, file)
caminnho_novo_arquivo = os.path.join(
root.replace(PASTA_ORIGINAL, NOVA_PASTA), file
)
shutil.copy(caminho_arquivo, caminnho_novo_arquivo)