def encode_filelist(self, path): filelist = getfilelist(path) # namefile = os.path.join(path, "xnote-index.json") # if os.path.exists(namefile): # 防止重复加密导致信息丢失 # bakname = "xnote-index-%s.json" % time.strftime("%Y_%m_%d_%H_%M_%S") # os.rename(namefile, os.path.join(path, bakname)) rename_dict = {} for index, file in enumerate(filelist): if file.type == "dir": continue newname = xutils.encode_name(file.name) if newname == file.name: continue newpath = os.path.join(path, newname) os.rename(file.path, newpath)
def test_encode_name(self): self.assertEqual("YS50eHQ=.x0", xutils.encode_name("a.txt")) self.assertEqual("YS50eHQ=.x0", xutils.encode_name("YS50eHQ=.x0"))