Automatically add student ID, name (or prefix in any other format) to the file

Copy the following code, save it to the text document, modify the suffix to bat

Drag the file that needs to be prefixed to the script to run

Procedure requirements:

Can be used by dragging

Rename without mechanically rigid

Keep original file name

Add a prefix before the original file name

Do not change the file suffix

Don’t look at a short line of code, it’s as difficult as breaking a code.

Both of the following are acceptable, but I prefer the latter, which is more concise:

ren "%~1" "181002304_海月_%~n1%~x1"

ren% 1 181002304_Kaigetsu_% ~ n1% ~ x1

Tips:

Drag in a file

File full name%~nx1

File name%~n1

Extension %~x1

%1 The first parameter refers to a string separated by spaces after the batch file name

If you drag and drop a file onto the script, then %1 represents this file, which is the first parameter

(You can use the shift command to shift the parameters to get more parameters)

%0 batch itself

Wildcard

Generally used for file name matching operations on the path

* Represents all characters

? Only represents one character

For example, copy all files in a folder copy path\*.* path

Copy files with the specified suffix copy path\*.jpg path

Copy the file whose first word is new and the last word is arbitrary, and the file name is limited to two words copy new?.xlsx path

One key to modify suffix

if exist "*.txt" (ren *.txt *.bat) else (ren *.bat *.txt)
:: The suffix of this file is cmd, which will not affect the use and will not be modified by itself

It is convenient to hand in the homework now~

Guess you like

Origin blog.csdn.net/weixin_43673589/article/details/109140938