Python Forum
Fetching html files from local directories
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fetching html files from local directories
#2
You use os.walk() which is recursive walking the whole tree.
Example:
import os

for root, dirs, files in os.walk(r'E:\1\web_title'):
    for file in files:
        if file.endswith('.html'):
            print(file)
Output:
Pipfile_1.html Pipfile_2.html Pipfile_3.html
join together then see that these files are in nested sub-folders.
import os

for root, dirs, files in os.walk(r'E:\1\web_title'):
    for file in files:
        if file.endswith('.html'):
            print(os.path.join(root, file))
Output:
E:\1\web_title\Pipfile_1.html E:\1\web_title\New folder\Pipfile_2.html E:\1\web_title\New folder\New folder\New folder\Pipfile_3.html
Reply


Messages In This Thread
RE: Fetching html files from local directories - by snippsat - Mar-20-2018, 01:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Python 3.12 cannot import local python files as modules sunflowerdog 25 20,785 Jul-31-2024, 01:52 PM
Last Post: sunflowerdog
  rename same file names in different directories elnk 5 2,495 Jul-12-2024, 01:43 PM
Last Post: snippsat
  [SOLVED] Loop through directories and files one level down? Winfried 3 2,386 Apr-28-2024, 02:31 PM
Last Post: Gribouillis
  Organization of project directories wotoko 3 1,541 Mar-02-2024, 03:34 PM
Last Post: Larz60+
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 1,409 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  Listing directories (as a text file) kiwi99 1 1,429 Feb-17-2023, 12:58 PM
Last Post: Larz60+
  Find duplicate files in multiple directories Pavel_47 9 7,190 Dec-27-2022, 04:47 PM
Last Post: deanhystad
  Tkinterweb (Browser Module) Appending/Adding Additional HTML to a HTML Table Row AaronCatolico1 0 1,894 Dec-25-2022, 06:28 PM
Last Post: AaronCatolico1
  fetching exit status hangs in paramiko saisankalpj 3 2,498 Dec-04-2022, 12:21 AM
Last Post: nilamo
  Fetching the port number using asyncio gary 0 1,536 Nov-01-2022, 02:53 AM
Last Post: gary

Forum Jump:

User Panel Messages

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