Removing numbers from file names

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
airkemp
Posts: 5
Joined: 03 Oct 2011 09:29

Removing numbers from file names

#1 Post by airkemp » 07 Oct 2011 08:56

Hi There

I have alot of files in the following format:
C:\Folder1\mkdy0000.bmp
C:\Folder2\mkdy0000.bmp
C:\Folder1\mkdy2074.bmp

I am looking to copy these files in the same directory keeping the numbers but renaming the first 4 chars, for example;

C:\Folder1\sess0000.bmp
C:\Folder2\sess0000.bmp
C:\Folder1\sess2074.bmp

I have the following, it is way off but i think it's heading in the right direction!:

Code: Select all

for /f "tokens=4 delims=y" %%a in ("%%~nf") do (set trunc=%%b)
for %%f in (%1\mkdy*.bmp) do ( copy %1\%%~nf.bmp %1\sess%trunc%.bmp)


Can anyone help?

Many Thanks

Alex

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Removing numbers from file names

#2 Post by aGerman » 07 Oct 2011 15:49

Does the file name always contain 4 letters and 4 digits?

Regards
aGerman

airkemp
Posts: 5
Joined: 03 Oct 2011 09:29

Re: Removing numbers from file names

#3 Post by airkemp » 10 Oct 2011 02:53

Hi There,

Yes they do.

Thanks

Alex

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Removing numbers from file names

#4 Post by dbenham » 10 Oct 2011 11:46

See your later post Renaming part of filename for code that should work with trivial modification.

Dave Benham

Post Reply