SHARE
TWEET

Untitled

a guest Oct 13th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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!")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top