-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenamer.py
More file actions
31 lines (25 loc) · 881 Bytes
/
Copy pathrenamer.py
File metadata and controls
31 lines (25 loc) · 881 Bytes
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
import os
def find(path, key):
#print('Find: %s' % path)
for filename in os.listdir(path):
fullname = os.path.join(path,filename)
if os.path.isdir(fullname):
find(fullname, key)
if key in filename:
print(filename)
def rename(path, str_from, str_to):
#print('Rename: %s' % path)
for filename in os.listdir(path):
fullname = os.path.join(path,filename)
if os.path.isdir(fullname):
rename(fullname, str_from, str_to)
new_name = filename.replace(str_from, str_to)
if not (filename==new_name):
print(filename, '->', new_name)
os.rename(fullname, os.path.join(path,new_name))
#if os.path.isfile(fullname):
if __name__ == '__main__':
path = './'
rename(path, ' ', '.')
print('\n')
find(path, '?')