1

I have this script, which works:

  FOR /F "delims=\" %%i IN ('dir /b /ad-h /o-d') DO (
    SET a=%%i
    GOTO :found
)
echo No subfolder found
goto :eof

:found
echo Most recent video created: &echo. & echo."%a%"
if /i "%a:~-3%"=="ESP" goto:next else goto:GBR
:GBR
if /i "%a:~-3%"=="GBR" goto:next else goto:SPE
:SPE
if /i "%a:~-3%"=="SPE" goto:next 

cd %a%
for %%a in (*) do rename "%%a" "%%~na-%a%%%~xa"
cd ..\
ren "%a%" "%a% - GBR"
echo.
echo %a% video has been processed
echo.
pause
exit /b

:next
echo.
echo. %a% Video already processed
echo.
pause

:exit
exit /b

I have tried to get an IF ELSE working however I cannot. I have had to use labels but it is not a clean way if I were to expand the search criteria.

Am I missing something?

This is what I tired, which does NOT work:

echo Most recent video created: &echo. & echo."%a%"
if /i "%a:~-3%"=="ESP" goto:next else 
if /i "%a:~-3%"=="GBR" goto:next else
if /i "%a:~-3%"=="SPE" goto:next

2 Answers 2

2

Try not to use a variable name similar to one already assigned with %something%:

for %%b in (*) do rename "%%a" "%%~nb-%a%%%~xb"

Update: (May not work. Just a concept)

setlocal enabledelayedexpansion

FOR /F "delims=\" %%i IN ('dir /b /ad-h /o-d') DO (
    SET a=%%i
    GOTO :found
)
echo No subfolder found
goto :eof

:found
echo Most recent video created: &echo. & echo."!a!"
if /i "%a:~-3%"=="ESP" goto:next else goto:GBR
:GBR
if /i "%a:~-3%"=="GBR" goto:next else goto:SPE
:SPE
if /i "%a:~-3%"=="SPE" goto:next 

cd !a!
for %%b in (*) do rename "%%b" "%%~nb-!a!%%~xb"
cd ..\
ren "!a!" "!a! - GBR"
echo.
echo !a! video has been processed
echo.
pause
exit /b

:next
echo.
echo. !a! Video already processed
echo.
pause

:exit
exit /b
Sign up to request clarification or add additional context in comments.

7 Comments

And wow this is actually knew to me: "%a:~-3%". I don't know what it does.
Looks at the last 3 characters? I am still trying to work it out.
@Arthor Yeah it's kind of like 8 or 9 years already since the last time I did cmd scripting. Reading the help infos a couple of times I must have known that only that I forgot it already :)
@Arthor How do you assign the values for %a%?
I have provided the full code for that part. Thanks
|
0
if /i "%a:~-3%"=="ESP" goto:next else goto:GBR
:GBR

the else goto:GBR is not needed here, because, if the comparison is not met, the script would continue with the next line anyway:

if /i "%a:~-3%"=="ESP" goto:next 
if /i "%a:~-3%"=="GBR" goto:next 
if /i "%a:~-3%"=="SPE" goto:next
echo found none of them.
Exit /b
:next
echo found one of them.

If you want to use else, the command has to be on the same line (the ( works as "start of a commandblock" and has to be on the same line than else):

if /i "%a:~-3%"=="ESP" goto:next else (
  if /i "%a:~-3%"=="GBR" goto:next else (
    if /i "%a:~-3%"=="SPE" goto:next
  )
)
:next

if fact, all of if, <comparison>, <command>, else and <command> have to be on the same line. You can outsmart the parser by using (blocks) instead of single commands:

if a == a (
  echo they are the same.
  echo yes, they are.
) else (
  echo they are different,
  echo not the same.
)

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.