SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import json
  2. import os
  3. import sys
  4. import time
  5.  
  6. filename = str((sys.argv[1]))
  7. rootdir = filename[:9]
  8. with open(filename, 'r') as f:
  9.     data = json.load(f)
  10.  
  11. inputpath = 'C:\\images\\empty\\'
  12. outputpath = rootdir + '\\' + rootdir
  13.  
  14. try:
  15.     os.mkdir(outputpath)
  16.     print("Directory " , outputpath ,  " Created ")
  17. except FileExistsError:
  18.     print(outputpath)
  19.  
  20. for dirpath, dirnames, filenames in os.walk(inputpath):
  21.     structure = os.path.join(outputpath, dirpath[len(inputpath):])
  22.     if not os.path.isdir(structure):
  23.         os.mkdir(structure)
  24.     else:
  25.         print("Folder does already exits!")
  26.  
  27. time.sleep(5)
  28.  
  29. for label in data:
  30.     #print(file['bicycle'])
  31.     for file in label['filenameList']:
  32.         newPath = file.replace(rootdir + '\\', rootdir + '\\' + rootdir + '\\' + label['type'] + "\\")
  33.         print('Moving to ' + newPath)
  34.         try:
  35.             os.rename(file, newPath)
  36.         except:
  37.             pass
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