import os
import sys
name = 'jpg.jpg'
path = '.'
for root, dirs, files in os.walk(path): # path 为根目录
for f in files:
if name in f.lower():
newname = f[0:-4]
print(newname)
os.rename(f, newname)
for root, dirs, files in os.walk(path): # path 为根目录
for f in files:
if ' ' in f:
print('有空格的',f)
newname= f.replace(' ', '')
os.rename(f, newname)
for root, dirs, files in os.walk(path): # path 为根目录
for f in files:
if '-' in f:
print('-连接线的:',f)
newname= f.replace('-', '_')
os.rename(f, newname)
for root, dirs, files in os.walk(path): # path 为根目录
for f in files:
if '—' in f:
print('—连接线的:',f)
newname= f.replace('—', '_')
os.rename(f, newname)
for root, dirs, files in os.walk(path): # path 为根目录
for f in files:
if '_' in f:
print('_大下划线的:',f)
newname= f.replace('_', '_')
os.rename(f, newname)
for root, dirs, files in os.walk(path): # path 为根目录
for f in files:
if not '_' in f or f[10:11] != '_' or f[-6:-5] != '_':
print('下划线位置不正确的:',f)
for root, dirs, files in os.walk(path): # path 为根目录
for f in files:
if 'png' in f :
print('是png格式的:',f)