0

I'm working on a simple batch file to save a text file for each JPG. The content of the txt file are input by user using set /p. For some reason when i used set /p with the for loop, the txt file did not show value input by user (it only shows: "ECHO is on").Any help would be highly appreciated! Thanks.

for %%Q in (*v.JPG) do (
set /p meas= "enter value "
echo %meas%>"%%~nQ.txt"
)
pause
  • 3
    Use the `search` facility in the top bar to find references to `delayed expansion` – Magoo Sep 30 '17 at 02:29
  • 3
    Possible duplicate of [Example of delayed expansion in batch file](https://stackoverflow.com/questions/10558316/example-of-delayed-expansion-in-batch-file) – Ryan Bemrose Sep 30 '17 at 02:40

2 Answers2

0

Magoo is right, Thank you! I had to use Enable delayed expansion, and then referto variables as !variable! and not %variable%. Unfortunately, there isn't documentation on Microsoft website on this issue, at least not on the 'set' command webpage.

-1
for %%Q in (v*.jpg) do ( set /p meas="enter value " && echo !meas! > %%~nQ.txt)

I tested this in just a cmd prompt but should work in a batch as well.

This will create a new file named <filename>.jpg.txt and will contain the value the user entered.

The key is to add && between set /p and echo.

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • https://stackoverflow.com/questions/38805476/enable-delayed-expansion-doesnt-work Magoo was correct. Not sure how it worked for me. Must have been user error on my part. – foodcoder86 Sep 30 '17 at 03:27