Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1.  
  2. import os
  3. from os import sep
  4. from os.path import join, split
  5. from subprocess import check_output
  6.  
  7.  
  8. def run_script(file_path):
  9. try:
  10. result = str(check_output(['file', file_path]))
  11. except Exception as e:
  12. result = str(e)
  13.  
  14. return result
  15.  
  16.  
  17. def check_dicoms(path):
  18. itemlist = []
  19. tabs = ["\t"]
  20.  
  21. with open('log.txt', 'w') as h:
  22. h.write("\n")
  23.  
  24. for root, dirs, files in os.walk(path):
  25. print(root)
  26.  
  27. rspit = split(root)
  28. ntabs = rspit[0].count(sep)
  29. croot = rspit[1]
  30.  
  31. itemlist.append(''.join(tabs * ntabs + [croot]))
  32. ntabs += 1
  33.  
  34. for filename in files:
  35. if filename == 'v_headers' or filename == 'v_headers.index':
  36. continue
  37. row = [filename, ' - ', run_script(os.path.join(root, filename))]
  38. itemlist.append(''.join(tabs * ntabs + row))
  39.  
  40. with open('log.txt', 'a') as h:
  41. h.write("\n".join(itemlist))
  42.  
  43. check_dicoms('asd')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement