DOS tricks

Batch file tricks

current directory of the batch file
%~dp0
cd /d %~dp0
xcopy %~dp0\*.* %~dp0\%var%\

use pushd instead of CD for UNC directories
If a network path is specified, PUSHD will create a temporary drive letter that points to that specified network resource and then change the current drive and directory, using the newly defined drive letter. Temporary drive letters are allocated from Z: on down, using the first unused drive letter found.
use %:~n,1% and %:~n,-1% to scan a string and remove heading and trailing blanks

pushd %~dp0
pushd “%~dp0:~n,-1%\SubDirectoryName”

%USERNAME%

Comments are closed.