Link to home
Create AccountLog in
Avatar of Andy Brown
Andy BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Detecting a file using a batch file

I am using a batch file during an installation routine that copies a shortcut onto the desktop.  At present it detects x86 or x64 OS and copies the correct shortcut.  However, it would be great if I could also detect the presence of a specific file and then copy the relevant shortcut based on this detection.  

Something like this example:

if EXIST "M:\TS.mdb" AND %PROCESSOR_ARCHITECTURE%==x86  copy "D:\Test Folder\TS.lnk"  c:\users\%username%\desktop

Any ideas?
if %PROCESSOR_ARCHITECTURE%==x86  copy "D:\Test Folder\A.lnk"  c:\users\%username%\desktop
if %PROCESSOR_ARCHITECTURE%==x64  copy "D:\Test Folder\B.lnk"  c:\users\%username%\desktop

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of István Nagy
István Nagy
Flag of Romania image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Andy Brown

ASKER

Spot on - thanks very much.
Avatar of Sumanbabu
Sumanbabu

Hi AndrewDBrown, sorry for interruption. I am also looking for the same.

Hi nagyistvan,

Solution worked well. Could you please explain how the preceded if condition ( if EXIST "M:\TS.mdb" ) helped?
Syntax:
IF {CONDITION} {ACTION}

In this case the IF %PROCESSOR_ARCHITECTURE%==x86  copy "D:\Test Folder\TS.lnk"  c:\users\%username%\desktop  
 part becomes the ACTION for the if EXIST "M:\TS.mdb   CONDITION
IF %PROCESSOR_ARCHITECTURE%==x86  copy "D:\Test Folder\TS.lnk"  c:\users\%username%\desktop  

The above line itself has a condition why do we need to add another condition
oops, i got it.