Mar-22-2021, 01:37 AM
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.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.