Python Forum

Full Version: Getting a list of filenames in a directory
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all, Python is very new to me, and I'm still finding my feet, so I apologise in advance if this is a daft question. I think this is my first post!

I use an app that downloads podcasts for me. I'm in the middle of writing a Python script to 'work on' the filenames, so that they are formatted the way I want them to be.

What I haven't been able to work out is how I can get a list of all the files in a particular directory, so that I can manipulate the name to the format I want, and then rename the file accordingly.

Any help you can give me would be very much appreciated!

Many thanks.
import os
for dirpath, dirnames, filenames in os.walk('.'):
    for f in filenames:
        print(f)
'.' is currently directory. Or you can put a path in to a specific directory
Thank you! Much appreciated.