Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- #os.mkdir('/tmp/X')
- fa = open('/tmp/X/a_file','w')
- fmr1 = open('/tmp/X/MR0001.dcm','w')
- fmr2 = open('/tmp/X/MR0002.dcm','w')
- fmr3 = open('/tmp/X/MR0003.dcm','w')
- fmr1.write('fmr1\n')
- fmr2.write('fmr2\n')
- fmr3.write('fmr3\n')
- fa.close()
- fmr1.close()
- fmr2.close()
- fmr3.close()
- root='/tmp/X'
- print (os.listdir('/tmp/X'))
- #['a_file', 'MR0003.dcm', 'MR0001.dcm', 'MR0002.dcm']
- i=1
- for path, subdirs, files in os.walk(root):
- for name in files:
- print (name)
- os.rename(os.path.join(path, name), os.path.join(path,'MR000'+ str(i)+'.dcm'))
- i=i+1
- print (os.listdir('/tmp/X'))
- #['MR0003.dcm', 'MR0004.dcm']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement