copy and rename files by extension

Hello,

I need to copy all files with extension "abc" on drive D:.  I need to retain the original file name except add .old to it.  This copy would occur on hundreds of directories, I would like to either use a batch or vbscript.  Thanks in advance for any help.
crash1624Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BeartlaoiCommented:
Where do you want the files to go?
In a directory structure like where they came from or all placed in a single folder (this could cause problems if same filename exists in two source folders)?
0
BeartlaoiCommented:
Assuming you want the same folder structure:
@echo off
if "%1" == "DOFILE" goto DOFILE

set SourceFolder=D:
set DestFolder=E:
for /R %SourceFolder% %%f in (*.abc) do call %0 DOFILE "%%f" "%DestFolder%%%~pnxf.old"
goto :EOF

:DOFILE
set pathname=%~dp3
set pathname=%pathname:~0,-1%
if not exist "%pathname%" echo md "%pathname%"
echo copy %2 %3

Open in new window

0
crash1624Author Commented:
Sorry, I thought that I posted my response.  I need to copy the file to the same directory.  So if the file is d:\testdirectory\test.abc I would need to copy the file test.abc and name it test.abc.old so there would be both test.abc and test.abc.old in the directory d:\testdirectory
0
BeartlaoiCommented:
Thats easy, same script just change line 5:
@echo off
if "%1" == "DOFILE" goto DOFILE

set SourceFolder=D:
set DestFolder=D:
for /R %SourceFolder% %%f in (*.abc) do call %0 DOFILE "%%f" "%DestFolder%%%~pnxf.old"
goto :EOF

:DOFILE
set pathname=%~dp3
set pathname=%pathname:~0,-1%
if not exist "%pathname%" md "%pathname%"
copy %2 %3 

Open in new window

I also removed the echo statements I had in there for testing
0
BeartlaoiCommented:
Since theres no need for folder managemt I was able to shrink it down to this:
set SourceFolder=D:\
for /R %SourceFolder% %%f in (*.abc) do copy "%%f" "%%f.old"

Open in new window

This goes inside a .cmd file
If you want a version that you can just paste to a command line then:
for /R D:\ %f in (*.abc) do copy "%f" "%f.old"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.