Imagine I have a txt file with a path like:
c:\programs\SRC_CODE\
How can I do a .bat file that open the txt file and get the string in order to set a variable witht the path catched from the txt?
thanks
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.
You have at least two possible options. You can either use
setand input redirection:where
set /pwill prompt for the path and the<mypath.txtwill actually work as if the contents of the text file where input directly.You also can use the
forcommand which can iterate over lines in a text file:Both methods actually have slightly different semantics on files with multiple lines. The first variant will store the first line of the file in the variable, the
forvariant will use the last line. Shouldn’t matter for single-line files, though. Oh, and it could happen that the first variant might output an empty line; I’ve added a redirect tonulto void that.