Wednesday, 4 July 2018

batch script to add remove prefix zero pad bulk file rename

batch script to add remove prefix zero pad bulk file rename
This post has two batch scripts:
1. Batch script to rename files with zero padded number series-prefix
2. Batch script to remove prefix of perticular length

1. Batch script to rename files with zero padded number series-prefix

This script will accept file-type to be searched and lenght of zero-padded prefix to be attached.
Usage: RenZeroPad.bat
Consider you have to rename / arrange a lot of mp3 files in a perticular sequence:
File names before execution:
fileX.mp3
fileY.mp3
fileZ.mp3
Command on dos prompt: RenZeroPad.bat mp3 4
File names with attached prefix:
0001 fileX.mp3
0002 fileY.mp3
0003 fileZ.mp3
[ad#ad-2-300×250]
The Batch Script to add zero pad digits prefix:
@echo off
setLocal EnableDelayedExpansion
set /a cnt=1
for %%i in (*.%1) do (
call :Set0Pad %2
set newName=!str! %%i
ren “%%i” “!newName!”
)
:Set0Pad
set padcntr=0000000000%cnt%
set str=%padcntr:~-%1%
set renstr=%str%
set /a cnt+=1
** Download available at the end of the page.

2. Batch script to remove prefix of perticular length

This script will accept file-type to be searched and lenght of prefix to be removed.
Usage: RemovePrefix.bat
Consider you have to rename / remove prefixes from a bunch of files:
0001_fileX.doc
0002_fileY.doc
0003_fileZ.doc
Command on dos prompt: RemovePrefix.bat mp3 5
Files will be renamed with removed prefixes as follows:
fileX.doc
fileY.doc
fileZ.doc
The Batch Script to remove prefix:
@echo off
setLocal EnableDelayedExpansion
set /a cnt=1
for %%i in (*.%1) do (
set str=%%i
set newstr=!str:~%2!
ren “%%i” “!newstr!”
)

0 comments:

Post a Comment