Advertisement
XenoTheStrange

Generate txt File Containing os.walk Content [Python]

Aug 20th, 2022 (edited)
1,115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import os
  4. tmp = list(os.walk(os.getcwd()))
  5. with open("walk.txt", "w") as file:
  6.     nl = "\n" #can't use \n inside of an f-string :/
  7.     for i in tmp:
  8.         file.write(f"Folder: {i[0]}{nl}Subfolders: {', '.join(i[1])}{nl}Files: {nl}{nl.join(i[2])}\n\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement