当前位置:网站首页>Rename all files in the folder with one click

Rename all files in the folder with one click

2022-06-21 11:42:00 Energetic wangdapeng

background

During the cloud disk course , I found that many course suffixes will add some special signs , Feeling affects the structured look and feel , At the same time, if the data has a code , This kind of identification will also affect the code to open directly . So I made a simple one key traversal program , And package it as exe.
 Insert picture description here

Ideas

  1. Given the file path of a parent directory , And the contents of the file name to be deleted ;
  2. Scan down to the root file name , Then the root file name is rename;

Code

import os
import sys

def get_files(filename):
    for filepath,dirnames,filenames in os.walk(filename):
        for filename in filenames:
            target_name = os.path.join(filepath,filename)
            # print(target_name)
            os.rename(target_name, target_name.replace(' Contents to be removed ',''))
    print(' Processing is complete ')
def convert_path(path):
    return path.replace(r'\/'.replace(os.sep, ''), os.sep)


if __name__ == '__main__':
    filepath = r'D:\00. Information \document-master\ Formal course materials '
    print(convert_path(filepath))
    get_files(filepath)

 Insert picture description here

In this way, one click name change is supported .

原网站

版权声明
本文为[Energetic wangdapeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211129107416.html