Batch Files Path

Microsoft Windows xp pro w/ sp3 multilin...
November 17, 2009 at 21:31:09
Specs: Windows XP SP3, P4 Celeron 2.4GHz/256 DDR266

Sorry for the basic question…

I’m trying to make a batch file that can launch exe’s in different folders.
I’d like to do this without a hard path like D:\Project\Installs\IE8\update\update.exe etc…
Maybe the PC I run it on later won’t have a D drive?

Assuming my root directory is something like D:\Project\Installs, how can I have a batch file (located in the ‘Installs’ folder) that can launch exe’s located in the ‘Installs’ folder and also sub-folders like IE8\update?

In case it matters, after I have a batch that can launch exe’s from multiple locations, I’ll wrap it with Installshield Package for the Web version 4 (setting to keep directory structure).



After reading again, this question doesn't look so clear anymore LOL.

I guess what I'm trying to ask is how to make whatever folder my batch is located in become the root folder (at least the root as far as the batch is concerned). So If I'm running a batch located in D:\Projects\Installs, Installs becomes the root folder and my batch would look like this:

update.exe /Q
folder3\regedit.exe /s mykey.reg
folder4\folder5\folder6\update.exe \q:n \r:n

the first update.exe and all the folders mentioned are located in D:\Projects\Installs but as far as the batch is concerned, the world starts with the folder Installs. Then if the whole thing got moved to a new location or drive letter, it would still work?

See More: Batch Files Path

Report •

November 18, 2009 at 02:52:32
for /R "%~dp0" %%j in (.) do (
  if exist "%%j\Your_Prog_To_Be_Executed" "%%j\Your_Prog_To_Be_Executed"

The above statement assumes the directory of its batch as the root and repeats the command browsing any subfolder. Obviously duplicate executables in different subfolders are not allowed and it is not efficient, but absolutely free from hard coded paths.

If however you just want to set the folder holding your batch as the root directory and then to manage the subfolders by your own, code

@echo off
pushd %~dp0



Report •
Related Solutions

Ask Question