@
zhouzm 感谢提供白名单思路
@
gamexg @
lanphon 感谢认真回复
#coding:utf-8
import os
def rename_file(file_path,file_holder,file_reciever):
#path 必须以 /开头
__author__ = 'wikinee'
file_full_name=file_path.split("/")[-1]
point1 = file_full_name.split(".")
double_types=['tar.gz','tar.bz2','
tar.bz','tar.Z']
if len(point1) <= 1:
filetype = ""
sp_filename = point1[0]
new_name = file_holder+"_"+sp_filename+"_"+file_reciever
elif len(point1) ==2:
filetype=point1[-1]
sp_filename = point1[0]
new_name = file_holder+"_"+sp_filename+"_"+file_reciever+"."+filetype
else:
newtype = point1[-2]+"."+point1[-1]
if newtype in double_types:
sp_filename = os.path.splitext(os.path.splitext(file_full_name)[0])[0]
@
9hills 你说的是上面这句是这意思吗?
filetype = newtype
new_name = file_holder+"_"+sp_filename+"_"+file_holder+"."+filetype
else:
sp_filename = os.path.splitext(file_full_name)[0]
filetype = point1[-1]
new_name = file_holder+"_"+sp_filename+"_"+file_holder+"."+filetype
return new_name