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
#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


Messages In This Thread
RE: Getting a list of filenames in a directory - by metulburr - Feb-03-2020, 01:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Next/Prev file without loading all filenames WilliamKappler 9 3,661 Apr-12-2024, 05:13 AM
Last Post: Pedroski55
  Very simple question about filenames and backslashes! garynewport 4 5,165 Jan-17-2023, 05:02 AM
Last Post: deanhystad
  select Eof extension files based on text list of filenames with if condition RolanRoll 1 2,301 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 5,483 Dec-11-2020, 07:07 PM
Last Post: tester_V
  Put all files in a directory into list. How? Denial 2 3,109 Sep-18-2020, 10:05 PM
Last Post: Larz60+
  How to double quote filenames (spaces)? Winfried 2 4,640 Jan-25-2020, 09:39 PM
Last Post: Winfried
  unable to list files in a directory christober 2 2,857 Sep-18-2019, 11:45 PM
Last Post: wavic
  reading directory paths from file to list malonn 6 5,453 Oct-26-2018, 11:19 PM
Last Post: malonn
  Escaping whitespace and parenthesis in filenames jehoshua 2 11,933 Mar-21-2018, 09:12 AM
Last Post: jehoshua
  List of pathlib.Paths Not Ordered As Same List of Same String Filenames QbLearningPython 20 20,566 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