Page 1 of 1

Removing numbers from file names

Posted: 07 Oct 2011 08:56
by airkemp
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

Re: Removing numbers from file names

Posted: 07 Oct 2011 15:49
by aGerman
Does the file name always contain 4 letters and 4 digits?

Regards
aGerman

Re: Removing numbers from file names

Posted: 10 Oct 2011 02:53
by airkemp
Hi There,

Yes they do.

Thanks

Alex

Re: Removing numbers from file names

Posted: 10 Oct 2011 11:46
by dbenham
See your later post Renaming part of filename for code that should work with trivial modification.

Dave Benham