Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import os
  2.  
  3. # Replace with the absolute path of you directory
  4. dir_path = '/Users/arpit/Documents/work/om/Data/McCutchionAndBhowmick_Songs'
  5. all_files = os.listdir(dir_path)
  6.  
  7. print("Shake that booty!")
  8.  
  9. for af in all_files:
  10.     with open(dir_path + "/" + af, 'r') as af_file:
  11.         counter = 1
  12.         new_dir_name = af.split(".")[0]
  13.         new_dir_path = dir_path + "/" + new_dir_name
  14.         if not os.path.isdir(new_dir_path):
  15.             os.mkdir(new_dir_path)
  16.  
  17.         split_paras = af_file.read().split("\n\n")
  18.         for sp in split_paras:
  19.             if sp.strip():
  20.                 new_file_path = new_dir_path + "/" + str(counter) + "_grinded.txt"
  21.                 with open(new_file_path, "w+") as grinded_file:
  22.                     grinded_file.write(sp.strip())
  23.                 grinded_file.close()
  24.                 counter += 1
  25.     af_file.close()
  26.  
  27. print("Grinding finished!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement