0

I am currently trying to create a batch script so I can sort multiple tiff images in a folder by moving it to other specific folder according to user input. What I achieved so far is: 1. Can loop through all the files in the folder 2. Can open the image viewer to view the tiff file 3. Close off the image viewer program 4. Move the tiff file to specific folder

However, I do not know why my set /p is not registering user's input value, when I tried to echo the input out.

cmd gave me "ECHO is off" message.

Appreciate if anyone could give me a hand to resolve this problem.

Many thanks G

@ECHO OFF
cd "C:\img\"
FOR /R %%f IN (*.tif) DO (
echo Current file is: %%f
start "" "C:\Program Files (x86)\Common Files\Global 360\Imaging\kodakprv.EXE" %%f
set /p name= Action:
IF "%name%" == "1" GOTO ONE
IF "%name%" == "2" GOTO TWO
IF "%name%" == "3" GOTO THREE
ECHO %name%
echo None of the above, BYE!
GOTO END

:ONE
echo "I pressed 1"
taskkill /IM kodakprv.EXE
move %%f "C:\img\1"
cls

:TWO
echo "I pressed 2"
taskkill /IM kodakprv.EXE
move %%f "C:\img\2"
cls

:THREE
echo "I pressed 3"
taskkill /IM kodakprv.EXE
move %%f "C:\img\3"
cls
)
:END
0

1 Answer 1

1
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
cd "C:\img\"
FOR /R %%f IN (*.tif) DO (
 echo Current file is: %%f
 start "" "C:\Program Files (x86)\Common Files\Global 360\Imaging\kodakprv.EXE" %%f
 SET "name="
 set /p name= Action:
 for %%v in (1 2 3) do IF "!name!" == "%%v" (
  set "validaction=Y"
  echo "I pressed %%v"
  taskkill /IM kodakprv.EXE
  move %%f "C:\img\%%v"
  pause
  cls
 )
 if not defined validaction (
  ECHO !name!
  echo None of the above, BYE!
  GOTO END
 )
)

:END

A few little problems.

First, you can't use labels within a code block (parenthesised series of commands) and second the old favourite, delayedexpansion - if a variable is changed within a code block then unless delayed expansion is in effect, the original value will be used. If delayed expansion is in effect, then %var% refers to the original value and !var! to the current (run-time) value.

Note also that set /p does not change the value of the variable if user response is simply Enter - -hence the set "name=" above to clear its value. Of course, you can omit that line and the last-entered value of name will be used again if you just press Enter.

There are many articles on SO about delayed expansion - just use the search feature.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.