__zero__

work with files

Jan 3rd, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. import os
  2.  
  3. #get files in path
  4. PATH = "C:\\YourFolder\\"
  5. files = [f for f in os.listdir(PATH) if os.path.isfile(os.path.join(PATH, f))]
  6. print(files) #Outputs list of files in PATH
  7.  
  8. #get extension of any file
  9. file = 'example.php'
  10. ext = os.path.splitext(file)[0]
  11. print(ext) #Outputs php
Advertisement
Add Comment
Please, Sign In to add comment