import os
import glob
from Tkinter import Tk
from tkFileDialog import askdirectory
fileDir = askdirectory()
print(fileDir)
#newfileDir=fileDir.replace('/','\\')
files = glob.glob("*.ac3")
print files
cnt = 0
for f in files:
if len(f) < 3 + 4:
os.rename(f, str(cnt)+f)
cnt += 1
print("renamed " + f)
我需要计算小于3个字符的文件名的字符长度,并将文件名重命名为numeric。
答案 0 :(得分:0)
试试这段代码:
import glob
import os
files = glob.glob("*.ac3")
cnt = 0
for f in files:
if len(f) < 3 + 4: # 4 is the length of the extension ".ac3"
os.rename(f, str(cnt)+f)
cnt += 1
print("renamed " + f)