import os if __name__ == ‘__main__‘: # 文件路径 dir_path = ‘/‘ # 获取路径下文件 dir_list = os.listdir(dir_path) # 获取文件数量 dir_nums = len(dir_list) # 遍历替换文件名 i = 1 for dir in dir_list: if dir.endswith(‘.下载‘): # os.rename需要文件路径 # 去掉‘.下载‘ new_name = dir[:-3] old_dir_name = os.path.join(dir_path, dir) new_dir_name = os.path.join(dir_path, new_name) try: os.rename(old_dir_name, new_dir_name) i += 1 except exception as error: print("error") continue print(‘文件总数:%d 现在是第几个文件:%d‘ % (dir_nums, i))
去掉网上拽下来的js'.下载'后缀 | 随便搞
时间: 2024-11-05 23:44:35