forked from kieranjol/IFIscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oeremove.py
executable file
·50 lines (42 loc) · 1.68 KB
/
oeremove.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
import os
import sys
from glob import glob
input = sys.argv[1]
if not os.path.isdir(input):
print 'Error - Not a directory - Please provide a directory as input. Exiting...'
sys.exit()
else:
os.chdir(input)
tiff_check = glob('*.tiff')
dpx_check = glob('*.dpx')
if len(dpx_check) > 0:
images = dpx_check
elif len(tiff_check) > 0:
images = tiff_check
else:
print 'no images found'
permission = ''
for i in images:
new_filename = ''
split_names = i.split('_')
if 'oe' in split_names[0]:
for x in split_names[1:-1]:
new_filename += x + '_'
new_filename += split_names[-1]
if not permission == 'y' or permission == 'Y':
permission = raw_input('\n**** Original filename = %s\n**** New filename = %s\n**** If this looks ok, please press Y, otherwise, type N\n' % ( i, new_filename))
while permission not in ('Y','y','N','n'):
permission = raw_input('\n**** Original filename = %s\n**** New filename = %s\n**** If this looks ok, please press Y, otherwise, type N\n' % ( i, new_filename))
if permission == 'n' or permission == 'N':
print 'Exiting at your command'
sys.exit()
elif permission =='y' or permission == 'Y':
os.rename(i, new_filename)
print '**** Renaming %s with %s' % (i, new_filename)
elif permission == 'y' or permission == 'Y':
os.rename(i, new_filename)
print '**** Renaming %s with %s' % (i, new_filename)
else:
print 'This does not need to be renamed - exiting...'
sys.exit()