Skip to content

Commit 5f29f47

Browse files
committed
add a rename filenames containing ips
1 parent ace21b5 commit 5f29f47

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

basic/regex/rename_ip.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
"""
4+
Topic: sample
5+
Desc : 重命名io文件名
6+
"""
7+
import sys
8+
import os
9+
import os.path as p
10+
import re
11+
from basic.regex.replace_ip import ip_maps
12+
13+
__author__ = 'Xiong Neng'
14+
15+
16+
def rename_file(path):
17+
files = os.listdir(path)
18+
for eachname in files:
19+
print(eachname)
20+
for k, v in ip_maps.items():
21+
if re.search(k + r'(?=\D+|\n|$)', eachname):
22+
new_name = re.sub(k + r'(?=\D+|\n|$)', v, eachname)
23+
os.rename(p.join(path, eachname), p.join(path, new_name))
24+
break
25+
26+
27+
if __name__ == '__main__':
28+
rename_file(sys.argv[1])

0 commit comments

Comments
 (0)