Python Forum
traverses directory recursively and displays files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
traverses directory recursively and displays files
#3
You have hint, why don't you use it?

I would do:

>>> import os
>>> help(os.walk)
Help on function walk in module os:

walk(top, topdown=True, onerror=None, followlinks=False)
    Directory tree generator.
    
    For each directory in the directory tree rooted at top (including top
    itself, but excluding '.' and '..'), yields a 3-tuple
    
        dirpath, dirnames, filenames
    
    dirpath is a string, the path to the directory.  dirnames is a list of
    the names of the subdirectories in dirpath (excluding '.' and '..').
    filenames is a list of the names of the non-directory files in dirpath.
    Note that the names in the lists are just names, with no path components.
    To get a full path (which begins with top) to a file or directory in
    dirpath, do os.path.join(dirpath, name).

/.../
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: traverses directory recursively and displays files - by perfringo - Apr-29-2020, 05:18 AM
homework - by Prani05 - Apr-30-2020, 08:56 AM
RE: homework - by anbu23 - Apr-30-2020, 09:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question How to print directory files (& timestamps) chatguy 3 1,390 Dec-29-2022, 07:19 AM
Last Post: ndc85430
  Opening files in same directory as script Emekadavid 3 2,587 May-28-2020, 06:50 PM
Last Post: Emekadavid
  Program that displays the number with the greatest amount of factors ilusmd 3 2,861 Nov-01-2018, 08:28 PM
Last Post: ichabod801
  Creating a variable that displays time groovydingo 3 2,948 Apr-17-2018, 04:46 AM
Last Post: tannishpage
  Homework that displays different weights Schmitlab 4 3,343 Oct-21-2017, 10:39 AM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

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