Skip to content

Commit cf7ea73

Browse files
authored
varrer pastas
1 parent 72742f7 commit cf7ea73

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

varredor de pastas.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
3+
def listar_arquivos_pastas(diretorio, saida):
4+
with open(saida, 'w', encoding='utf-8') as arquivo_saida:
5+
for raiz, pastas, arquivos in os.walk(diretorio):
6+
nivel = raiz.replace(diretorio, '').count(os.sep)
7+
indentacao = ' ' * 4 * nivel
8+
arquivo_saida.write(f"{indentacao}[Pasta] {os.path.basename(raiz)}\n")
9+
10+
sub_indentacao = ' ' * 4 * (nivel + 1)
11+
for arquivo in arquivos:
12+
arquivo_saida.write(f"{sub_indentacao}- {arquivo}\n")
13+
14+
if __name__ == "__main__":
15+
PATH_B = "/media/code/DRIVERS"
16+
saida_arquivo = "saida.txt"
17+
listar_arquivos_pastas(PATH_B, saida_arquivo)
18+
print(f"Listagem concluída! Verifique o arquivo {saida_arquivo}")

0 commit comments

Comments
 (0)