user3474706
user3474706

Reputation: 33

Batch - Load a path (text) from a text file into a variable

In my code, I save a path to a folder inside of a text file. My goal now is to load that path again from the text file and use it to upload a modified version of the folder to the original location.

So far I have tried this, without success:

set savePath="more test.txt"
xcopy /e testFolder %savePath%

Any ideas would be greatly appreciated

Upvotes: 1

Views: 94

Answers (2)

Rafael
Rafael

Reputation: 3122

FOR command can help you.

for /f %%a in (test.txt) do (set "savePath=%%a")

It will set savePath as the last line of test.txt

Upvotes: 0

unclemeat
unclemeat

Reputation: 5207

If you know the file path will be on the on the first line of the text file, then you can use the set command with the /p switch.

Set /p savePath=<test.txt

Upvotes: 1

Related Questions