robertvari

List folders with sorting

Apr 25th, 2019
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. import os
  2.  
  3. path = "D:/PythonSuli"
  4. folders = []
  5. files = []
  6. for i in os.listdir(r"D:\PythonSuli"):
  7.     if os.path.isdir(os.path.join(path, i)):
  8.         folders.append(i)
  9.     else:
  10.         files.append(i)
  11.  
  12. folder_content = sorted(folders, key=lambda x:x.lower()) + sorted(files, key=lambda x:x.lower())
  13. print(folder_content)
Advertisement
Add Comment
Please, Sign In to add comment