import os;
def rename():
i=0
path="F:\test";
filelist=os.listdir(path)
for files in filelist:
i=i+1
Olddir=os.path.join(path,files);
if os.path.isdir(Olddir):
continue;
filename=os.path.splitext(files)[0];
filetype=os.path.splitext(files)[1];
Newdir=os.path.join(path,str(i)+filetype);
os.rename(Olddir,Newdir)
rename()
import os
path_01='D:/User/wgy/workplace/data/notMNIST_large.tar.gar'
path_02='D:/User/wgy/workplace/data/notMNIST_large'
root_01=os.path.splitext(path_01)
root_02=os.path.splitext(path_02)
print(root_01)
print(root_02)
结果:
('D:/User/wgy/workplace/data/notMNIST_large.tar', '.gar')
('D:/User/wgy/workplace/data/notMNIST_large', '')