How to batch rename folders and files with bat

I wrote an article on renaming a folder a long time ago, and found that it is slightly imperfect. Its main function is to add characters before the folder name, or add characters after the folder name. Some netizens responded that the function is too good. single. Today, I took a closer look at the bat batch code, which can completely rename folders and completely rename files, and now share with you.

How to batch rename folders and files with bat
 

Tools/Materials

 
  • windows notepad

Method/Step - Rename Folder

 
  1. 1

    Take a few new folders as an example.

    How to batch rename folders and files with bat
  2. 2

    Create a new txt text document with any file name

    How to batch rename folders and files with bat
  3. 3

    Edit this txt text file and enter the following characters

    set a=1000

    setlocal EnableDelayedExpansion

    FOR /f "tokens=*" %%i IN ('dir /a:d /b') DO (

    set /A a+=1

    ren "%%i" "电影!a!"

    )

    then save

    How to batch rename folders and files with bat
  4. 4

    After saving, change the file extension to bat, and there is a prompt to select "Yes"

    How to batch rename folders and files with bat
  5. 5

    Double-click to run this bat batch file, and after a little delay, the folders have all been renamed

    How to batch rename folders and files with bat
  6. 6

    The code mainly pays attention to the following two points, which can be modified at will

    How to batch rename folders and files with bat
  7. 7

    After these two modifications, the name of the renamed folder after running also changes.

    How to batch rename folders and files with bat
    END

Method/Step 2 - Rename the file

 
  1.  

    Taking renaming the txt file as an example, also create a new bat file first, and the code is as follows

    @echo off

    set a=00

    setlocal EnableDelayedExpansion

    for %%n in (*.txt) do (

    set /A a+=1

    ren "%%n" "小说!a!.txt"

    )

    Pay attention to the 4 places marked in red, you can make changes

    How to batch rename folders and files with bat
  2.  

    After double-clicking, the effect is as follows

    How to batch rename folders and files with bat
    END

Precautions

 
  • The characters in the bat file should use English characters
  • Every time you use it, pay attention to modifying several marked places in the code first

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325070180&siteId=291194637