-
Notifications
You must be signed in to change notification settings - Fork 3
/
file_renamer.py
36 lines (32 loc) · 1.23 KB
/
file_renamer.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
from lxml import etree
import os, sys
image_directory = os.getcwd()
arr = os.listdir(os.path.join(image_directory,'combine'))
count=0
for file in arr:
if file.endswith(".jpg"):
count=count+1
print(count)
count_n=1
for file in arr:
if file.endswith(".jpg"):
#print(file)
string=file.split('.jpg' , 0)[0]
org=string.split('.')[0]
im=str(org)+'.xml'
im1=str(org)+'.jpg'
#print(im)
new_xml='image_'+str(count_n)+'.xml'
#print(im1)
new_jpg='image_'+str(count_n)+'.jpg'
count_n=count_n+1
print(count_n)
if os.path.isfile(os.path.join(os.path.join(image_directory,'combine'),im)) :
try :
print(im)
print(new_xml)
os.rename(os.path.join(os.path.join(image_directory,'combine'),im),os.path.join(os.path.join(image_directory,'combine'),new_xml))
os.rename(os.path.join(os.path.join(image_directory,'combine'),im1),os.path.join(os.path.join(image_directory,'combine'),new_jpg))
except WindowsError:
print ( 'File already Renamed' )
print (str(count_n-1) +' '+ 'File Names Changed')