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%
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
%0is the full path to the .bat file itself (if run from another directory) and~dpiis 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,%~dp0does the same thing in one go.