Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import os, sys
  2.  
  3.  
  4. def convert(path):
  5.     try:
  6.         files_dirs = os.listdir(path)
  7.         files_only = [ i for i in files_dirs if not os.path.isdir(i)]
  8.         py_files = [i for i in files_only if i.endswith('.py')]
  9.         print('found py files: ', py_files)
  10.         print('[...] converting files ...')
  11.         os.chdir(path)
  12.         for file in py_files:
  13.             convert_formula = file[:-3] + '.txt'
  14.             print('converting: ', file)
  15.             os.rename(file, convert_formula)
  16.         print('[+] Done')
  17.     except FileNotFoundError:
  18.         print('[-] invalid path ! ')
  19.        
  20.    
  21. convert(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement