Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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,065 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