Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Batch Rename Multiple Files


  • Please log in to reply

#1
AverageJoeUser

AverageJoeUser

    New Member

  • Member
  • Pip
  • 1 posts
I have a directory where files are saved periodically. When they come in, the format is "filename_12345.pdf". The "12345" part is an autonumber. I need to run a batch file from time to time to remove the autonumber part.

This is what I have, but not working:

@echo off
setlocal enabledelayedexpansion
for /f %%F in ('dir /b c:\Documents and Settings\username) do (
set newname=%%~nF
set newname=!newname:~0,-8!.pdf
)

Thanks for any help with this.
  • 0

Advertisements


#2
Ztruker

Ztruker

    Member 5k

  • Technician
  • 7,091 posts
Using ren seems to work (mostly) :lol:

D:\Temp\work>dir
Volume in drive D is D370_D
Volume Serial Number is 9402-7174

Directory of D:\Temp\work

03/01/2013 09:01 PM <DIR> .
03/01/2013 09:01 PM <DIR> ..
03/01/2013 08:55 PM 0 filename1_12345.pdf
03/01/2013 08:55 PM 0 filename2_12346.pdf
03/01/2013 08:55 PM 0 filename3_12347.pdf
3 File(s) 0 bytes
2 Dir(s) 61,983,436,800 bytes free

D:\Temp\work>ren filename*_*.pdf filename*_.pdf

D:\Temp\work>dir
Volume in drive D is D370_D
Volume Serial Number is 9402-7174

Directory of D:\Temp\work

03/01/2013 09:02 PM <DIR> .
03/01/2013 09:02 PM <DIR> ..
03/01/2013 08:55 PM 0 filename1_.pdf
03/01/2013 08:55 PM 0 filename2_.pdf
03/01/2013 08:55 PM 0 filename3_.pdf
3 File(s) 0 bytes
2 Dir(s) 61,983,436,800 bytes free

D:\Temp\work>


You might be able to make use of the ? in the ren command, depending on the format of filename.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP