Shorten a file name using a batch

April 14, 2009 at 02:03:48
Specs: Windows XP
Hi, I would like to create a batch file that cuts a name like "YEAR_SERVICE_INVOICENR_CONTRACTNR.pdf" to "INVOICENR.pdf" where all of them are numbers..
Can you please help me or address me to the right command? Is it possibile to do it using DOS commands? Thanks a lot.

See More: Shorten a file name using a batch

Report •

April 14, 2009 at 02:59:42
If all files' names have the same reported structure, i.e. numbers delimited by underscores, then

:: MYREN.BAT  Usage: myren Folder_Name
@echo off
pushd %*
for /F "tokens=1-4 delims=_" %%a in ('dir /B *.pdf') do (
  ren %%a_%%b_%%c_%%d %%c.pdf
:: End_Of_Batch

WARNING: Try on a test directory before a massive renaming as the script was not tested.

Report •

April 14, 2009 at 05:23:36
Fantastic!! It works well.
Thanks a lot, IVO. Alessandro

Report •

Related Solutions

Ask Question