Caner
Caner

Reputation: 59178

Batch file: for parameters

I am having trouble understanding what does following windows batch file do, can somebody explain:

for /f %%i in ("%0") do set curpath=%%~dpi
cd /d %curpath% 
/*Some other code...*/
cd /d %curpath%

Upvotes: 0

Views: 808

Answers (1)

Alex K.
Alex K.

Reputation: 175796

%0 is the full path to the .bat file itself (if run from another directory) and ~dpi is a modifier to extract the drive and directory from a path omitting the file name, so this snippet sets the current drive & directory to the one in which the batch file lives.

I can't see the reason for using a FOR, %~dp0 does the same thing in one go.

Upvotes: 3

Related Questions