http://www.csnserver.com
Click here for Low cost website hosting!

IP Address Lookup
IP Address

Microsoft Windows Tips And Tricks!



Welcome!

Dos Commands that display drive and directory where a file lives



Below is a script example that can be used in batch files to determine where the file you are running lives. This is useful when writing scripts for moving or installing files where you need to know the current working drive and or directory as well.

Here is a simple batch/Script that will show the above data:

@echo off
echo Current location of this file and its status:
echo.
echo Current dir = %CD%
echo.
Echo Script dir = %~dp0
echo.
echo Batch File Path (where it lives and its name) = %0
echo.
echo Current Drive = %~d0
echo.
echo Path to batch file = %~p0
echo.
pause

If you run the above batch file with the name "Dos Commands that display drive and directory where a file lives.cmd" as we did you will get this output:

Current location of this file and its status:

Current dir = C:\download\OS\Win Tips

Script dir = C:\download\OS\Win Tips\

Batch File Path (where it lives and its name) = "C:\download\OS\Win Tips\Dos commands that display drive and directory where a file lives.cmd"

Current Drive = C:

Path to batch file = \download\OS\Win Tips\

Press any key to continue . . .

Now that you see how these variables work in a batch it will be easy to put them to use.

Thanks for visiting mswintips.com.

Return to Index Page


Valid HTML 4.01 Transitional
Copyright 2018 CSN All Rights Reserved