Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to sort os.walk list?
#6
If you want to visit the directories in order as well, you can also sort, but you have to sort the existing list, not return a new one.

Adding
dirs.sort()
after the os.walk() call will sort the directories and then the processing of them will be in sorted order as well.
Reply


Messages In This Thread
How to sort os.walk list? - by Denial - Oct-09-2020, 06:52 AM
RE: How to sort os.walk list? - by DPaul - Oct-09-2020, 07:39 AM
RE: How to sort os.walk list? - by Denial - Oct-09-2020, 10:16 AM
RE: How to sort os.walk list? - by ibreeden - Oct-09-2020, 10:34 AM
RE: How to sort os.walk list? - by Denial - Oct-09-2020, 10:38 AM
RE: How to sort os.walk list? - by bowlofred - Oct-09-2020, 03:27 PM
RE: How to sort os.walk list? - by Denial - Oct-10-2020, 05:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a list of dictionaries by the only dictionary key Calab 2 652 Apr-29-2024, 04:38 PM
Last Post: Calab
  list.sort() returning None SmallCoder14 8 666 Mar-19-2024, 09:49 PM
Last Post: SmallCoder14
Smile Python & MSGraph - Learning to Walk ITMan020324 2 457 Feb-04-2024, 04:37 PM
Last Post: ITMan020324
Photo a.sort() == b.sort() all the time 3lnyn0 1 1,352 Apr-19-2022, 06:50 PM
Last Post: Gribouillis
  list sort() function bring backs None CompleteNewb 6 4,212 Mar-26-2022, 03:34 AM
Last Post: Larz60+
  EasySNMP Walk/BulkWalk pylance 3 2,132 Nov-29-2021, 12:00 PM
Last Post: pylance
  [solved] Sort list paul18fr 5 2,949 Aug-18-2021, 06:34 AM
Last Post: naughtyCat
  Sort List of Lists by Column Nju 1 12,299 Apr-13-2021, 11:59 PM
Last Post: bowlofred
  os.walk question DPaul 2 2,365 May-31-2020, 02:08 PM
Last Post: DPaul
  os.walk(Path("path_string")) giving error Kumarkv 4 3,914 May-10-2020, 08:46 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