import os, os.path as osp, sys, shutil, argparse, re, glob, time, argparse, pdb def rename(dir): for root, dirs, files in os.walk(dir): pdb.set_trace() for file in files: if file.endswith('.npy'): new_name = file.split('_')[-1] new_name = osp.join(root, new_name) old_name = os.path.join(root, file) os.rename(old_name, new_name) print('Renamed {} to {}'.format(old_name, new_name)) if __name__ == '__main__': dir = '/home/zjp/DeepDynamicFashion/REC-MV/data/yanzhi_a/parsing' rename(dir)