Rename the specified directory using python file
- [File] specified directory file is renamed ~ 715B
#Copyright 2012 wuyuangui.
#www.iplaypy.com python教程
import os
path = 'F:\Python\open project\SGI\SGI_STL'
paths = path.replace('\\', '//')
paths = paths + '//'
print paths
files = os.listdir(paths)
for i in files:
#print(i)
pat = None
pat = paths + str(i)
if os.path.isdir(pat):
pass
elif os.path.isfile(pat):
if not str(pat).endswith('.h'):
list = pat.split('//')
patt = list[list.__len__() - 1] + '.h'
print(str(i) + str(patt))
os.rename(pat, str(pat + patt))
#os.rename(str(pat + patt), pat)
print('regfile:' + pat)
else:
pass
Recommended reading:
Basics zero Python's most detailed source of tutorials
2019 Python Reptile Learning Roadmap full version
Why Python can be firmly secured the first card AI Artificial Intelligence Language
Python rise, TIOBE list of programming languages a new high!