''' 找到原始目录中重复的 输入文件名的确定: 上层文件夹, xxx_20 当前文件名, 146_xxx,146转16进制,为92。 两字符串连接: 2092,,即为文件名。 ''' import os import sys from maplet_tools import get_sig_arr inws = r'd:\maplet_dvk\MapPicDir' all_arr = get_sig_arr(inws) def finddupl(lst): """找出 lst 中有重复的项 (与重复次数无关,且与重复位置无关) """ exists, dupl = set(), set() for item in lst: if item in exists: dupl.add(item) else: exists.add(item) return dupl
# -*- coding:cp936 -*- # import os import sys import arcpy import maplet_tools if __name__ == '__main__': inws = r'd:\maplet_dvk\MapPicDir' now_arr = maplet_tools.get_sig_arr(inws) for wroot, wdirs, wfiles in os.walk(inws): for wdir in wdirs: new_sig = maplet_tools.get_uu4d() while new_sig in now_arr: new_sig = maplet_tools.get_uu4d() if wdir.endswith('_tt'): now_arr.append(new_sig) raw_path = os.path.join(wroot, wdir) new_path = os.path.join(wroot, ''.join([wdir[:-2] , 's' , new_sig])) print(raw_path) print(new_path) os.rename(raw_path, new_path) print('For files: ') for wroot, wdirs, wfiles in os.walk(inws): for wfile in wfiles: (qian, hou) = os.path.splitext(wfile) new_sig = maplet_tools.get_uu4d()