Python Forum
How to access all xlsx files in all subdirectories?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to access all xlsx files in all subdirectories?
#3
With pathlib you get a better abstraction.

from pathlib import Path

document_dir = Path(r'C:\Users\igyulavics\Desktop\dir1')
for xlsx_file in document_dir.glob('**/*.xlsx'):
    # xlsx_file is a Path object
    # if you use old libraries, you have to use str(xlsx_file) to convert the Path to a str
    print(xlsx_file)
This code finds all .xlsx files recursive. This should work also on Windows.
Look here: https://docs.python.org/3/library/pathli....Path.glob
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: How to access all xlsx files in all subdirectories? - by DeaD_EyE - Mar-19-2019, 11:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  sharepoint: Access has been blocked by Conditional Access policies CAD79 0 2,446 Jul-12-2024, 09:36 AM
Last Post: CAD79
  .py pandas matplotlib .xlsx files QubeStory 1 1,475 Mar-23-2023, 09:38 AM
Last Post: buran
  comparison of two xlsx files Jlyk 4 3,175 Sep-20-2021, 07:13 AM
Last Post: Jlyk
  Extracting information from .xlsx files hobbyist 0 2,255 Jan-06-2021, 07:20 PM
Last Post: hobbyist
  How to loop in python over subdirectories and copy the output to other subdirectories arielma 1 2,555 Oct-22-2020, 03:38 PM
Last Post: bowlofred
  Moving Files From Subdirectories To Another Directory Harshil 5 5,621 Oct-06-2020, 10:52 AM
Last Post: ndc85430
  Creating Excel files compatible with microsoft access vkallavi 0 2,175 Sep-17-2020, 06:57 PM
Last Post: vkallavi
  How to access files from shared folder? samandhare 4 53,101 Jun-25-2020, 11:14 AM
Last Post: samandhare
  How can I speed up my openpyxl program reading Excel .xlsx files? deac33 0 4,737 May-04-2020, 08:02 PM
Last Post: deac33
  Making .exe file that requires access to text and html files ClassicalSoul 0 2,071 Apr-23-2020, 05:03 PM
Last Post: ClassicalSoul

Forum Jump:

User Panel Messages

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