List files from a folder using os.listdir

0

I want to list the files in a folder using os.listdir in Python but it does not return anything. The code I made:

import os

def rename_files():
    # (1) obter nomes de arquivos de uma pasta
    file_list = os.listdir(r"C:\FotosUdacity\prank")
    rename_files()   
    
asked by anonymous 09.11.2017 / 01:11

1 answer

0

Does this help you?

from os import listdir

def listar_arquivos(caminho=None):
    lista_arqs = [arq for arq in listdir(caminho)]
    return lista_arqs

if __name__ == '__main__':
    arquivos = listar_arquivos(caminho="/seu/caminho/")
    print(arquivos)
    
09.11.2017 / 08:52