Windows uses a batch file to change the file name (including the serial number) in the specified directory

For pictures downloaded from the Internet, the default name is a relatively long character string composed of many letters and numbers, which is not easy for people to remember and is troublesome to use. As shown below:

The purpose of this article is to write a batch file to rename all files with the extension jpeg in the directory to date plus serial number format. The content of the batch file (assuming the file name is d:\temp\my.bat) is as follows:

@echo off 
setlocal EnableDelayedExpansion
rem setlocal DisableDelayedExpansion 
set a=1
set a=2 & echo !a!
set /a n=1000
for %%i in (D:\Images\temp\*.jpeg) do (
	echo %%i
	set /a n=n+1
	ren %%i 20221118_!n!%%~xi
)

 Double-click the above batch file directly with the mouse (ie "d:\temp\my.bat"). After the program runs, all files in the directory will be renamed, and the result is shown in the figure below.

Related references:

  1. Windows batch-for command detailed explanation. https://www.toutiao.com/article/7063789245617701384/?log_from=4d1a90af605c1_1668781678221  .
  2. Popular and thorough interpretation of the delay variable of batch processing. Popular and thorough interpretation of the delay variable of batch processing- Leveraging the future fulcrum- Blog Park  .
  3. Batch delay variable. Batch delay variable_Turbo_J's Blog-CSDN Blog  .
  4. Variable delay of Windows Bat script (Setlocal enabledelayedexpansion). https://blog.csdn.net/weixin_33979745/article/details/93514309?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault %7ECTRLIST%7ERate-2-93514309-blog-79608760.pc_relevant_multi_platform_whitelistv4&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-2-93514309-blog-79608760.pc_relevant_multi_platform_whitelistv4&utm_relevant_index=3  

Guess you like

Origin blog.csdn.net/Alexabc3000/article/details/127931603