Copy a file using Batch Files and rename it

Microsoft Windows xp professional w/serv...
April 20, 2010 at 07:40:53
Specs: Windows XP
I have a .exe file in C:\DOCUME~1\user\Local Settings\Apps\2.0\....../some flder(changes everytime)
I want to copy it to C:\Program FIles

This is what i have done

set SearchIn=%userprofile%
set FileToSearch=dd.exe
cd "%SearchIn%"
attrib /s \dd.exe

IF EXIST dd.exe copy "%FileToSearch%" "C:\Program Files"
rem dd.exe somename.exe

if not %ErrorLevel% == 0 echo some error, errorlevel is %ErrorLevel% & pause


Please help me make it sucessful

See More: Copy a file using Batch Files and rename it

Report •

April 20, 2010 at 14:48:34
one way, if dd.exe only exists in one location:
xcopy /s dd.exe "c:\program files"
if %errorlevel% equ 4 echo file dd.exe not found

another way, using your attrib approach (but "dir" instead):
for /f "tokens*" %%a in ('dir /b /s dd.exe') do set xx=%%a
if not defined xx (echo file not found) else (copy %%a "c:\program files")

Report •

April 21, 2010 at 05:23:26
Hey nbrane

Thanks for the reply but it didn't work either.i have tried using the dir command every time in install this program it installs itself in a different folder in the user profile ..i need to copy it to program files to make it available to all the users and rename it for proper functionality

Any other ideas.....?.
I am a newbie in bat scripting so complete script would be of great help

Report •

April 21, 2010 at 11:43:11
well, with the /s on the dir, it should work, as should the xcopy /s which, although aimed at copying entire directory-structures, will also work for single-file copy of a file located "downstream" in the dir.structure.
attrib /s could be used, but you gotta monkey around with it more.

Report •

Related Solutions

Ask Question