I have zero experience with writing batch files but my goal does not seem difficult. I'm trying to write a small script that will prompt a user to enter an ID number and then search a directory of .jpgs and copy any pictures containing the ID number to a separate directory. The .jpgs are names xxxxxx_zzz.jpg where xxxxxx is the ID number up to 6 digits and zzz is the sequence number. For example, one ID can have many pictures: 123456_001.jpg, 123456_002.jpg, 123456_003.jpg, etc.
I've played with several IF
and GOTO
commands, but I seem to be diverging from my goal. I know the two IF
statements I currently am using below are garbage, but I left them in the syntax to convey the direction I think I should be moving in.
I can't get the IF
statements to use the GOTO
commands. I also don't think I fully understand how labels are supposed to work.
@ECHO OFF
CLS
:START
DEL /q C:\Users\ADMIN\Desktop\temp\*.*
:GETINPUT
set /p propkey=Enter the Property Key of pictures to retrieve.:
IF EXIST C:\Users\ADMIN\Desktop\photos\*%propkey%_???.jpg GOTO Success
IF "%propkey%"=="" ECHO No Property Key was entered. GOTO START
:Success
ECHO Pictures from Property Key %propkey% will now be moved to the Temp folder on the Desktop. && PAUSE
COPY "C:\Users\ADMIN\Desktop\photos\*%propkey%*.jpg" "C:\Users\ADMIN\Desktop\temp\"
START C:\Users\ADMIN\Desktop\temp\
:END