-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenomeia.py
36 lines (25 loc) · 816 Bytes
/
renomeia.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Python3 code to rename multiple
# files in a directory or folder
import os
PATH="/media/rodrigo/OS/TESTE_antes_SAP/compilado_semana10/74_arquivos/"
# Finding nth occurrence of substring
def str_index(ini_str,sub_str,occurrence):
val = 0
for i in range(0, occurrence):
val = ini_str.find(sub_str, val)
return val
### acrescenta a string .sqlite ao final do nome
def extensao(name):
src = name + ".sqlite"
return src
# Function to rename multiple files
def main():
for count,filename in enumerate(os.listdir(PATH)):
posicao = str_index(filename, '_2',1)
MI = filename[posicao+1 : posicao+10]
dest = PATH + extensao(MI)
src = PATH + filename
os.rename(src, dest)
main()