How to create a batch file which work for both Program Files and Program Files(x86)?

Sharad picture Sharad · Apr 9, 2012 · Viewed 57.5k times · Source

I have created a batch file which automatically copy a .sql file to the path of installed Jasper server(it could be any software installation directory).

This is my batch script--

C:\PROGRA~2\JASPER~1.0\mysql\bin\mysql.exe -u root -proot < create_database.sql

that is working when jasper is installed in Program Files(x86). How can i generalize it for both Program Files and Program Files(x86).

Answer

RenniePet picture RenniePet · Feb 25, 2013

Here's one way of doing it, which I've copied from this source: http://social.msdn.microsoft.com/Forums/zh/winforms/thread/69dc2aac-9956-40a0-9826-da48b9003a8e

SET ProgFiles86Root=%ProgramFiles(x86)%
IF NOT "%ProgFiles86Root%"=="" GOTO win64
SET ProgFiles86Root=%ProgramFiles%
:win64

"%ProgFiles86Root%\name of program" "arguments, etc."