-
Notifications
You must be signed in to change notification settings - Fork 0
/
renamePhotos.py
43 lines (36 loc) · 1.2 KB
/
renamePhotos.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
import os
from shutil import copyfile
def list_files(dir):
fileName = ''
for root, dirs, files in os.walk(dir):
carpeta = os.path.basename(root)
if carpeta.isdigit():
fileName = carpeta
if len(files) > 0:
i = 1
for file in files:
oldName = root+'\\'+file
newName = str(fileName) + str(i)
extension = os.path.splitext(file)[1]
os.rename(oldName,root+'\\'+newName+'.jpg')
print('viejo:',root+'\\'+file,'extension:',extension, newName+'.jpg')
i += 1
print('-----------------------------------------------------')
def folders():
count = 0
for x in range(105,0,-1):
path = str(x)
os.makedirs(path)
seguir = True
j = 1
while seguir:
imagen = str(x) + str(j) + '.jpg'
if os.path.isfile(imagen) :
print(imagen)
count += 1
copyfile(imagen, path + '/' + imagen)
else:
seguir = False
j += 1
print('cantidad:',count)
list_files('imagenes-arboles-nueva')