0

I have these 3 files in a folder and they are all located in C:\Max:

attach.bat:

@echo off
cd %~dp0
diskpart /s run.txt

run.txt:

select vdisk file="C:\Max\maximus.vhd" 
attach vdisk

maximus.vhd: a virtual hard disk drive which is mounted via the other 2 files.

How can attach.bat get the current directory location and write it to run.txt?


I know how to write to the txt files, but I can't find the current directory. I want to be able to mount this from anywhere on the fly and any directory.

For example:

echo select vdisk file="C:\Max\maximus.vhd" >> C:\Max\run.txt
echo attach vdisk >> C:\Max\run.txt
bjb568
  • 9,826
  • 11
  • 45
  • 66
  • @echo off echo select vdisk file="%~dp0maximus.vhd" >> %~dp0\run.txt echo attach vdisk >> %~dp0\run.txt timeout /t 2 /nobreak cd %~dp0 diskpart /s run.txt yes this is working!!!!!!! – punktoe Jul 29 '14 at 06:04

1 Answers1

1

The solution is using %~dp0 to reference the drive and path of the batch file as Anton Tykhyy suggested.

@echo off
echo select vdisk file="%~dp0maximus.vhd" 1>"%~dp0run.txt"
echo attach vdisk 1>>"%~dp0run.txt"
timeout.exe /t 2 /nobreak
cd /D "%~dp0"
diskpart.exe /s run.txt
Community
  • 1
  • 1
Mofi
  • 38,783
  • 14
  • 62
  • 115