Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
examples using os.walk()
#11
here is a script that shows the first 10 paths from os.walk() and the first 10 paths from the sort of paths from os.walk().
import os
from os.path import join
from sys import argv

argv.pop(0)
if not argv:
    exit('need one argument naming a file tree')

apex = argv.pop(0)
r = 64*'-'

paths = [apex]
for x,xd,xf in os.walk(apex):
    for d in xd:
        paths.append(join(x,d))
    for f in xf:
        paths.append(join(x,f))

names = paths[:]
names.sort()

for x in range(10):
    print(paths[x])
print(r,flush=True)

for x in range(10):
    print(names[x])
print(r,flush=True)
here is the result on my forums account:
Output:
t2a/forums /home/forums 5> py try_oswalk_sort.py /home/forums /home/forums /home/forums/requests /home/forums/ijson /home/forums/.subversion /home/forums/animage /home/forums/.screenshots /home/forums/aws /home/forums/futurist.se /home/forums/Templates /home/forums/.ssh-auth ---------------------------------------------------------------- /home/forums /home/forums/.ICEauthority /home/forums/.Xauthority /home/forums/.alias /home/forums/.alias.6204310359228514 /home/forums/.alias.6204310951603521 /home/forums/.audacity-data /home/forums/.audacity-data/AutoSave /home/forums/.audacity-data/Plug-Ins /home/forums/.audacity-data/audacity.cfg ----------------------------------------------------------------
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
examples using os.walk() - by Skaperen - Mar-19-2021, 12:28 AM
RE: examples using os.walk() - by Larz60+ - Mar-19-2021, 12:52 AM
RE: examples using os.walk() - by Skaperen - Mar-20-2021, 02:20 AM
RE: examples using os.walk() - by Larz60+ - Mar-20-2021, 02:35 AM
RE: examples using os.walk() - by Skaperen - Mar-20-2021, 05:37 PM
RE: examples using os.walk() - by DeaD_EyE - Mar-20-2021, 06:16 PM
RE: examples using os.walk() - by buran - Mar-20-2021, 06:17 PM
RE: examples using os.walk() - by DeaD_EyE - Mar-20-2021, 06:30 PM
RE: examples using os.walk() - by Skaperen - Mar-21-2021, 10:13 PM
RE: examples using os.walk() - by Skaperen - Mar-21-2021, 10:43 PM
RE: examples using os.walk() - by Skaperen - Mar-22-2021, 01:37 AM
RE: examples using os.walk() - by buran - Mar-22-2021, 06:37 AM
RE: examples using os.walk() - by Skaperen - Mar-22-2021, 05:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  features examples by release costa_shul 2 2,594 Sep-06-2020, 11:35 AM
Last Post: costa_shul
  list of compliances of all special methods - examples nzcan 2 2,864 Sep-01-2018, 08:33 PM
Last Post: Windspar
  why i don't like os.walk() Skaperen 20 20,241 Jan-11-2018, 08:39 AM
Last Post: Skaperen
  WSGI working examples Skaperen 1 3,546 May-29-2017, 10:45 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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