Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import os
  2. #os.mkdir('/tmp/X')
  3. fa = open('/tmp/X/a_file','w')
  4. fmr1 = open('/tmp/X/MR0001.dcm','w')
  5. fmr2 = open('/tmp/X/MR0002.dcm','w')
  6. fmr3 = open('/tmp/X/MR0003.dcm','w')
  7. fmr1.write('fmr1\n')
  8. fmr2.write('fmr2\n')
  9. fmr3.write('fmr3\n')
  10. fa.close()
  11. fmr1.close()
  12. fmr2.close()
  13. fmr3.close()
  14. root='/tmp/X'
  15.  
  16. print (os.listdir('/tmp/X'))
  17. #['a_file', 'MR0003.dcm', 'MR0001.dcm', 'MR0002.dcm']
  18.  
  19. i=1
  20. for path, subdirs, files in os.walk(root):
  21.     for name in files:
  22.         print (name)
  23.         os.rename(os.path.join(path, name), os.path.join(path,'MR000'+ str(i)+'.dcm'))
  24.         i=i+1
  25.  
  26. print (os.listdir('/tmp/X'))
  27. #['MR0003.dcm', 'MR0004.dcm']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement