python批量重命名【截取文件名前六个字符 】
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 打开文件 path = "/home/landv/Desktop/l/" dirs = os.listdir( path ) # 输出所有文件和文件夹 for file in dirs: if os.path.splitext(file)[1] == '.jpg': new=file[0:6]#截取文件名前六个字符 os.rename(file,new)#进行重命名 #print file
本文来自博客园,作者:landv,转载请注明原文链接:https://www.cnblogs.com/landv/p/10790093.html

浙公网安备 33010602011771号