Try this:
:Start
@echo off
cls
:: store source folder
set _sd=C:\Users\ADMIN\Desktop\photos
:: store target folder
set _td=C:\Users\ADMIN\Desktop\temp
:CheckFolders
if not exist %_sd% echo Source folder not found.&goto End
if not exist %_td% echo Target folder not found.&goto End
:: wipe target folder
del /q %_td%\*.*
:GetKey
set /p _key=Enter the property key:
if '%_key'=='' echo No property key entered. Please retry.&goto GetKey
if not exist "%_sd%\*%_key%*.jpg" echo No photos matched the key.&goto End
echo Copying pictures to %_td%...
copy "%_sd%\*%_key%*.jpg" "%_td%"
:OpenFolder
start "%windir%\explorer.exe" "%_td%"
:End
A label is a way to arbitrarily designate a line in a batch file. It is used by the GOTO
command to change the usual top-to-bottom progression of command execution, specifying which line should be processed next. As you probably figured out, using IF
commands in unison with GOTO
allows for conditional processing, such as when values are met or errors are encountered.
Another use of a label could be for documentation or clarity. In my example above, "CheckFolders" isn't used by a GOTO
, but it lets the programmer hint at what that section of code does.