List files from a folder using.listdir

Asked

Viewed 2,149 times

0

I want to list the files of a folder using the os.listdir in Python but returns nothing. 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()   

1 answer

0


It helps 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)
  • I had doubt about how to make such a listing and your answer help me a lot. Thank you Bruno!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.