Advertisement
Guest User

pliki

a guest
Jan 17th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys
  3. import os
  4. if len(sys.argv)<3:
  5.     print("Podaj dwa parametry: katalog wejsciowy i wyjsciowy.")
  6.     sys.exit()
  7. in_dir=sys.argv[1]
  8. out_dir=sys.argv[2]
  9. if not os.path.isdir(in_dir):
  10.     print("Katalog wejsciowy nie istnieje!")
  11.     sys.exit()
  12. if not os.path.isdir(out_dir):
  13.     print("Katalog wyjsciowy nie istnial i zostal utworzony.")
  14.     os.makedirs(out_dir)
  15. for fname in os.listdir(in_dir):
  16.     if fname.endswith('.txt'):
  17.         path_in=in_dir+"/"+fname
  18.         path_out=out_dir+"/all.txt"
  19.         with open(path_in) as file_in:
  20.             my_list=file_in.read().splitlines()
  21.         with open(path_out, "a") as file_out:
  22.             for el in my_list:
  23.                 file_out.write(el+"\n")
  24.     else:
  25.         print("W katalogu wejsciowym nie istnieja pliki *.txt!")
  26.         sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement