Python Forum
Getting a list of filenames in a directory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a list of filenames in a directory
#1
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.
Reply
#2
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
Recommended Tutorials:
Reply
#3
Thank you! Much appreciated.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Very simple question about filenames and backslashes! garynewport 4 1,832 Jan-17-2023, 05:02 AM
Last Post: deanhystad
  select Eof extension files based on text list of filenames with if condition RolanRoll 1 1,475 Apr-04-2022, 09:29 PM
Last Post: Larz60+
  List of error codes to find (and count) in all files in a directory tester_V 8 3,587 Dec-11-2020, 07:07 PM
Last Post: tester_V
  Put all files in a directory into list. How? Denial 2 2,081 Sep-18-2020, 10:05 PM
Last Post: Larz60+
  How to double quote filenames (spaces)? Winfried 2 3,415 Jan-25-2020, 09:39 PM
Last Post: Winfried
  unable to list files in a directory christober 2 2,004 Sep-18-2019, 11:45 PM
Last Post: wavic
  reading directory paths from file to list malonn 6 4,022 Oct-26-2018, 11:19 PM
Last Post: malonn
  Escaping whitespace and parenthesis in filenames jehoshua 2 9,636 Mar-21-2018, 09:12 AM
Last Post: jehoshua
  List of pathlib.Paths Not Ordered As Same List of Same String Filenames QbLearningPython 20 15,180 Nov-16-2017, 04:47 PM
Last Post: QbLearningPython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020