0
@echo off     

cd "G:\Stuff\Util"
start launch.bat

cd "G:\Stuff"                    
for /L %%a in (1,1,10) do (
Start batch2.bat
exit 0          
)

^my code

I need to know how to make my batch file run those others on different PCs. When I plug in it a different pc, the drive letter may change. How do I solve this?

  • 1
    Did you check this post: https://stackoverflow.com/questions/10868613/detect-usb-and-copy-to-usb-drive-using-batch-script – funcoding Oct 18 '17 at 12:50

1 Answers1

0

Figured it out.

@echo off     

pushd %~d0
cd "\Stuff\Util"
start launch.bat

cd "\Stuff"                  
for /L %%a in (1,1,10) do (
Start batch2.bat
exit 0          
)
  • `pushd %~d0` should read `pushd "%~d0\"` to really point to the root directory of the drive containing the batch script... – aschipfl Oct 18 '17 at 13:55
  • I would suggest using `Call` instead of `Start` and you shouldn't really need both the `CD` and `PushD` commands. Incidentally both `CD \ ` and `PushD \ ` will set a new current directory to the root directory of the path which was current at the time of invokation. _Whilst aschipfl is correct to append the trailing back slash to your `PushD` line, I can see no reason for the double quotes, `PushD %~d0\ `_ – Compo Oct 18 '17 at 15:33