Let me first explain what I am trying to accomplish: I have a GoPro camera and when recording multiple time-lapses you end up with a big pile of img files, two time-lapses are divided by a number in the file name. Gxxxyyyy is how the files are labeled, the y stands for which time-lapse the picture belongs to and x what picture in the time-lapse.
I am trying to create a program that puts every time-lapse in a different folder (sorting by the numbers on the x position); I am using batch because I already had some experience with it.
This is the program I wrote:
@echo off
set loop=0
set fn=1
set session=1
:sort
if %loop% LSS 1000 (
if %fn% GTR 99 (
ROBOCOPY D:\Bureaublad\Output\Pictures D:\Bureaublad\Output\Pictures\Session%session% G%fn%*.JPG
if %ERRORLEVEL% EQU 1 set /A session=%session%+1
)
if %fn% LSS 10 (
ROBOCOPY D:\Bureaublad\Output\Pictures D:\Bureaublad\Output\Pictures\Session%session% G00%fn%*.JPG
if %ERRORLEVEL% EQU 1 set /A session=%session%+1
) ELSE (
if %fn% LSS 100 (
ROBOCOPY D:\Bureaublad\Output\Pictures D:\Bureaublad\Output\Pictures\Session%session% G0%fn%*.JPG
if %ERRORLEVEL% EQU 1 set /A session=%session%+1
)
)
set /A fn=%fn%+1
set /A loop=%loop%+1
goto sort
)
I was trying to use the errorlevel value to determine if the copy was successful, because if it was the next copy had to be to another folder which is what i used the session variable for. But it always copies everything into the "session1" folder and not into separate folders even though i have files with different numbers on the x position.
I tried figuring out what the problem was and used "echo %ERRORLEVEL%" followed by a pause, right after the robocopy commands and every time it just said 0 even though files were copied.
That is the issue and I can't figure out why the errorvalue doesn't change.
ERRORLEVEL
is a built-in value, not an environmental variable, so you don't need the%
around it.IF ERRORLEVEL 1
is the usual way you test for it being set; note there are no%
and it doesn't useEQU
. – Ken White