可以通过增加多位随机数字,重复执行以下python 代码代码,
然后在执行之前分享的python数据处理1--对批量数据重名
https://blog.csdn.net/u012514944/article/details/89705504
就可以做到了!
for category in os.listdir(dirname):
print(category)
catdir = os.path.join(dirname,category)
if not os.path.isdir(catdir):
continue
files = os.listdir(catdir)
print(files)
#count = startcount
fisrt = 1;
for cur_file in files:
print("正在处理" + category + "分类下的" + cur_file)
filename = os.path.join(catdir,cur_file)
#count = count + 1
second = random.randint(0,9)
third = random.randint(0,9)
fourth = random.randint(0,9)
fifth = random.randint(0,9)
sixth = random.randint(0,9)
t = time.time()
seventh = int(round(t*1000))
#原来的文件路径
oldDir = os.path.join(catdir,cur_file)
if os.path.isdir(oldDir):
continue
filename = os.path.splitext(cur_file)[0]
filetype = os.path.splitext(cur_file)[1]
newDir = os.path.join(catdir,str(fisrt)+str(second)+str(third)+str(fourth)+str(fifth)+str(sixth)+str(seventh)+filetype)
os.rename(oldDir,newDir)