Python Forum
Loop through all files in a directory?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop through all files in a directory?
#2
You could use
import os
root = '.'
files = [os.path.join(d, f) for d, _, files in os.walk(root) for f in files]
print(files)
« We can solve any problem by introducing an extra level of indirection »
Reply


Messages In This Thread
RE: Loop through all files in a directory? - by Gribouillis - Apr-22-2024, 07:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  deleting files in program files directory RRADC 6 3,589 Aug-21-2024, 06:11 PM
Last Post: snippsat
  Filer and sort files by modification time in a directory tester_V 5 2,700 May-02-2024, 05:39 PM
Last Post: tester_V
  [SOLVED] Loop through directories and files one level down? Winfried 3 2,554 Apr-28-2024, 02:31 PM
Last Post: Gribouillis
  File loop curiously skipping files - FIXED mbk34 10 3,219 Feb-10-2024, 07:08 AM
Last Post: buran
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 1,475 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  change directory of save of python files akbarza 3 3,782 Jul-23-2023, 08:30 AM
Last Post: Gribouillis
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 8,464 Jun-27-2023, 01:17 PM
Last Post: diver999
  Monitoring a Directory for new mkv and mp4 Files lastyle 3 2,913 May-07-2023, 12:33 PM
Last Post: deanhystad
  How to loop through all excel files and sheets in folder jadelola 1 9,859 Dec-01-2022, 06:12 PM
Last Post: deanhystad
  Read directory listing of files and parse out the highest number? cubangt 5 5,630 Sep-28-2022, 10:15 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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