发布时间:2019-09-27 07:10:22编辑:auto阅读(2559)
为什么使用python批量重命名而没有使用shell,python对文字的处理更灵活,对于文件名中的空格不会出现报错。
代码:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
@author:Aiker Zhao
@file:rename_all.py
@time:下午10:29
"""
import os
path = "M:\\bd1\\都挺好\\"
new_path = "M:\\bd1\\doutinghao\\"
for file in os.listdir(path):
# print(file)
if os.path.isfile(os.path.join(path, file)) == True:
if file.find('.mp4') < 0:
print(file)
else:
file_number = file.split('@')[0]
print(file_number)
new_file_name = '都挺好' + file_number + '.mp4'
print(new_file_name)
os.rename(os.path.join(path, file), os.path.join(new_path, new_file_name))
对于不规范的文件重命名,可以使用excel表格,通过对表格的处理来重命名,
上一篇: python3 爬“斗图啦”
下一篇: Python3 与 Python2共存
51027
50406
41021
37886
32351
29248
28130
22965
22929
21256
1131°
1836°
1480°
1419°
1705°
1509°
2169°
3739°
3671°
2583°