Skip to main content

Posts

Showing posts with the label os.listdir

Find all the files in a directory

Find all the files in a directory There are a lot of way to do it, let’s start with the first. Using os.listdir() Italiano BasterĂ  importare il modulo os (import os) e poi usare la funzione os.listdir() (stampandola sulla console con print, per esempio). Inglese You just have to import the os module and you can use the os.listdir method (showing it on the screen with print, for example). >>>  import  os >>>  print (os. listdir ()) All the other ways… This has been taken from my stackoverflow answer… Get a list with the files I have made also a short video here:  Video os.listdir(): get files in current dir (Python 3) The simplest way to have the file in the current dir in Python 3 is this. It’s really simple, use the os module and the listdir() function and you’ll have the file in that dir (and eventual folders that are in the dir, but you will not have the file in the subdirectory, for that you can use walk – ...