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%
%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.