Bat batch using Python and modify the file name

I have not encountered a folder there are a lot of files, and these files were varied, doing have. But then there is another task, let's say all of these files renamed.

Although not difficult, but good Fana.

Well, today, oranges give you about a relatively simple method.

Bat batch using Python and modify the file name

 

For example, I just want to rename all of these csv file. Although oranges picture csv file naming is regular. But let's not pretend Kazakhstan.

Then came the first question: how to get the names of all files in a folder within it?

We use Python program to solve this problem.

import os
dir = "E:/Desktop/新建文件夹"#需要修改的路径
for root, dirs, files in os.walk(dir):
for file in files:
print(os.path.join(file))
Bat batch using Python and modify the file name

 

Select copy it to get all the files in the folder name you ~

Then, coming second question: How old name and new name corresponds to it?

This time we need Excel to help out friends.

The instruction and the old and new names have filled in the following format.

The command line is fixed oh.

Bat batch using Python and modify the file name

 

Finally, finally turn Bat file played it:

First, we have a lot of files within the folder to create a txt file before now. The Excel spreadsheet will just copy all the contents inside the folder txt to go inside.

Bat batch using Python and modify the file name

 

The txt extension changed to bat after saving.

Bat batch using Python and modify the file name

 

Double-click to run

Bat batch using Python and modify the file name

 

This Jiuhaola.

Finally, there are a little mischievous Here he comes: ren modify the file name is flawed. One of the most annoying is that if the file name with a special character, ren may modify unsuccessful. In the next oranges on how to solve this part of our Kazakhstan

Guess you like

Origin www.cnblogs.com/chengzhiya/p/12538574.html
Recommended