批量重命名.py 730 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # File : 批量重命名.py
  4. # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
  5. # Date : 2022/12/12
  6. import os
  7. def main(path):
  8. # base_path = os.path.dirname(os.path.abspath(__file__)) # 当前文件所在目录
  9. # print(base_path)
  10. files = os.listdir(path)
  11. print(files)
  12. for file in files:
  13. if file.endswith('2.js'):
  14. print(file)
  15. os.rename(path+'/'+file,path+'/'+file.replace('2.js','.js'))
  16. elif file.endswith('2[飞].js'):
  17. print(file)
  18. os.rename(path+'/'+file,path+'/'+file.replace('2[飞].js','[飞].js'))
  19. if __name__ == '__main__':
  20. path = r'F:\drpy源\js'
  21. main(path)