0

I'm trying to biuld a chain from batches but something prevents to start my 2nd batch from executing because it brings stuff from the first batch (I guess)

this is my folder structure:

%~dp0..\× H\
          |______ [00]\
          |         |_________________ 123.jpg
          |                            # hard.cmd
          |
          |
          |______ [00] - cópy\ 
                    |_________________ 345.jpg
                                       # hard.cmd

and I start in "%~dp0..\× H\[00]\# hard.cmd" where content of my # hard.cmd is:

TITLE "R"
CHCP 1250 > NUL 2>&1
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /F %%a IN ('ECHO PROMPT $H ^| CMD') DO SET BS=%%a
SET "CC=- cópy"
SET "NAME=0"

:IN
   IF NOT EXIST "SOUR CE.png" ( GOTO :CHECK )
   GOTO :START

:START
   IF EXIST "SOUR CE.jpg" IF EXIST "SOUR CE.png" ( GOTO :ASK )

:ASK
   ECHO      RESET JOB ?     y / n
   SET /P "ANSWER=X%BS%                  "
   IF '%ANSWER%' == ''      GOTO :START
   IF '%ANSWER%' == 'n'     GOTO :NO
   IF '%ANSWER%' == 'y'     GOTO :YES

:NO 
   DEL /Q /A /F "SOUR CE.jpg" "%NAME%.jpg"
   GOTO :CHECK

:YES
   DEL /Q /A /F "%NAME%.jpg"
   GOTO :CHECK

:CHECK
   IF EXIST "*.jpg" IF EXIST "*.png" ( GOTO :ERROR )
   IF EXIST "%NAME%.jpg"             ( GOTO :ERROR )
   GOTO :CONTINUE

:CONTINUE
   IF EXIST "*.jpg" ( IF NOT EXIST "SOUR CE.jpg" ( REN "*.jpg" "SOUR CE.jpg" ) )
   IF EXIST "SOUR CE.jpg" ( app.exe -i "SOUR CE.jpg" -o "%NAME%.jpg"
                           GOTO :NEXT )
   GOTO :NEXT

:ERROR
   ECHO this is error
   PAUSE > NUL
   GOTO :NEXT

:NEXT
   IF EXIST   "%~dp0..\[00] %CC%\"     (
   CALL       "%~dp0..\[00] %CC%\# hard.cmd"
   IF EXIST   "%~dp0..\[00] %CC%"  ( REN "%~dp0..\[00] %CC%"  "[02]" ) )
   ECHO DONE

note that content of both batches (# hard.cmd) is same

if I run these batches separately then they execute as they should, however if I try to chain them as demonstrated above then pops up :ERROR label of the second batch even if the 2nd batch/folder doesnt violte the set of rules. and as result 2nd batch shall not execute as it should (as the first one)

apart of CALLing I tried even STARTing, but non of my tries worked. these are the things I already tried:

CALL                      "%~dp0..\[00] %CC%\# hard.cmd"
START CALL                "%~dp0..\[00] %CC%\# hard.cmd"
START "" CALL             "%~dp0..\[00] %CC%\# hard.cmd"
START "" CMD /C           "%~dp0..\[00] %CC%\# hard.cmd"
START "" CMD /K           "%~dp0..\[00] %CC%\# hard.cmd"
START "" /WAIT  /B        "%~dp0..\[00] %CC%\# hard.cmd"
START "" /WAIT /B       /D"%~dp0..\[00] %CC%" "# hard.cmd"
START "" /WAIT /B CALL    "%~dp0..\[00] %CC%\# hard.cmd"

and few more combinations... where did I make a mistake ? all I want is to run 2nd batch separately after the 1st one shall finish. preferable in the same window (but if that is not possible then 1st batch/window shall open 2nd batch /window and first one will close right afer 2nd one starts running)

as I see it then 2nd batch brings ruleset from 1st batch, because when the 1st batch finish then in folder [00] there is a file "0.jpg" and this triggers the :ERROR label of the 2nd batch.

thank you to reading this and for any help

  • You have a lot of implicitness in these scripts.... It seems that the :ERROR routine is called if either of these two conditions are TRUE.... 1.) if both any .jpg and .png files exist in the ~\[00] - cópy folder or 2.) if 0.jpg exists in the ~\[00] - cópy folder. Does that sound correct? Consider redoing your logic to be more explicit and pass in variables with a CALL for the paths, etc. and you could likely use one script for both/all folders rather than having the same logic in multiple scripts if you continue having trouble—being explicit always works well for me. – Pimp Juice IT May 29 '18 at 5:05
  • @PimpJuiceIT yes, that is correct. I needed to build OR switch so if folder have both (*,jpg and *.png then) OR if "%NAME%.jpg" id in the folder then I want to end it with :ERROR label. I am explicitly looking for executing these batches separatly from each other. how come there is no way how to achieve this? I really feel I just missing some important minority in :NEXT label where I try to CALL/START for the next batch – user902300 May 29 '18 at 5:39
  • To test, rather than using "%~dp0..\[00] %CC%\# hard.cmd" use C:\Folder\path\× H\[00]\# hard.cmd explicitly like that for each rather than the "%~dp0..\~ and see if that resolves it. If so, then check those variables with %~dp0.. and echo those to see if they are correct or what. Just an idea but I can only assume it's something related to that, or the # sign in the cmd file name or something along those lines. I'm not sure without digging into it with more detail but I'm tight on time right now. I thought the issue was going to :ERROR initially so that's why I asked about that. – Pimp Juice IT May 29 '18 at 5:57
0

found the missing piece PUSHD "%~dp0..\[00] %CC%\":

:NEXT
   IF EXIST   "%~dp0..\[00] %CC%\"     (
   PUSHD      "%~dp0..\[00] %CC%\"
   CALL       "%~dp0..\[00] %CC%\# hard.cmd"
   IF EXIST   "%~dp0..\[00] %CC%"  ( REN "%~dp0..\[00] %CC%"  "[02]" ) )
   ECHO DONE

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.