我有一些文件,其名称如下:
AES_Trace=1149990_key=8f9a79d1a94d99a1b5806e803eac1b48_Plaintext=5321b7a34af144c03dbd66bbc61fdc53_Ciphertext=c2684c4713f2f46cb9e2d256c72b15ec.npy
我尝试修改每个文件的名称,我需要将数字设置为49990:
import os
path_For_Numpy_Files='C:\\Users\\user\\Desktop\\tt'
os.chdir(path_For_Numpy_Files)
list_files_Without_Sort=os.listdir(os.getcwd())
list_files_Sorted=sorted((list_files_Without_Sort),key=os.path.getmtime)
for file in list_files_Sorted:
start = file[0:file.index("Trace=")+6]
end = file[file.index("_key"):]
num = file[len(start): file.index(end)]
if num>400000:
print (num)
new_name= start
new_name = start + str(int(num) - int('1100000')) + end
print('\n'.join([start, end, num, new_name]))
os.rename(os.path.join(path_For_Numpy_Files, file), os.path.join(path_For_Numpy_Files, new_name))
但相反减法我有一个补充:新名称是:
-2249990
AES_Trace=-2249990_key=8f9a79d1a94d99a1b5806e803eac1b48_Plaintext=5321b7a34af144c03dbd66bbc61fdc53_Ciphertext=c2684c4713f2f46cb9e2d256c72b15ec.npy
那么,请问如何解决这个问题?
我期望得到的是:49990