BAT batch modify/restore file names - add fixed fields at the end

Environment: win7

Language: not involved

Logic: Use bat (script to implement this function) to modify file names in batches - add fixed fields at the end

Object: Suitable for batch modification and batch restore of files with the same length to be processed. (When the lengths are inconsistent, the modification script is available, but the restore script is not available.)

#Batch modification, add the field "_190401", the .bin in the for statement is the file format, if the original file is in other formats, just modify the .bin in the two places of this sentence to the corresponding statement. For example, the .txt statement is modified to: "for /f %%i in ('dir /ad /b *.txt') do ren %%i %%~ni!s!.txt"

@echo off
rem 2019-4-1 18:38:51
rem no cavities lm
setlocal EnableDelayedExpansion
set s=_190401
for /f %%i in ('dir /ad /b *.bin') do ren %%i %% ~ni!s!.bin
echo Add bin type files in batches to add time fields, successful!
pause
 

#Batch restore, the original file has a fixed length, so the set n=9 directly specified here, 9 is the length of the reserved field. Same as above, .bin in the for loop is the format of the file to be processed. If it is a .jpg file, it can be modified as: "for /f "delims=" %%a in ('dir /ad /b *.jpd') do ("

@echo off
rem April 1, 2019 18:29:13
rem no cavities lm
setlocal enabledelayedexpansion
set n=9
for /f "delims=" %%a in ('dir /ad /b *.bin') do (
set "name=%%~na"
ren "%%~a" "!name:~0,%n%!%%~xa"
)
echo Restore the bin type file name to the original naming method, complete!
pause

Guess you like

Origin blog.csdn.net/i_likechard/article/details/102565886