0
cd /d F:\Translated\DocsForPOST
for %%f in (*.json) do (
        if exist %%f (
            script.py POST list of params here
        )
        IF %ERRORLEVEL% EQU 0 (
            move %%f F:\Translated\DocsForPOST\archive
                )
    )

I have this code that I'm trying to move a file ONLY if the .py doesn't throw an error, and if it does just leave the file in place. This isn't working for me, and I'm not sure why. Any insight is appreciated.

AlliDeacon
  • 1,365
  • 3
  • 21
  • 35
  • 2
    There is no need to check if the file exists. The FOR command would not iterate the file if it didn't exist. – Squashman May 04 '21 at 18:49
  • @Squashman this is a batch script that is in production currently, I am only trying to add exception handling using the `%ERRORLEVEL%` variable to skip any files that have erred out. – AlliDeacon May 04 '21 at 18:54
  • 1
    The easiest solution would be to use conditional execution. `script.py POST list of params here &&move %%f F:\Translated\DocsForPOST\archive`. – Squashman May 04 '21 at 19:10
  • 1
    What about not using a variable form for the error level? For example: Line 1. `@For %%G In ("F:\Translated\DocsForPOST\*.json") Do @(python.exe "script.py" POST list of params here using I assume "%%~fG"`, Line 2: `If Not ErrorLevel 1 Move /Y "%%~fG" "%%~dpGarchive")` – Compo May 04 '21 at 19:47
  • @Compo that got me a little closer! Thanks so much, it's very appreciated! – AlliDeacon May 04 '21 at 19:52
  • Either it solves the issue you raised in your question, or it doesn't! Please clarify @AlliDeacon. – Compo May 04 '21 at 19:53
  • @AlliDeacon did you not understand the link I posted or the conditional execution code? – Squashman May 04 '21 at 19:56
  • @Compo I ended using: `If Not ErrorLevel 1 Move /Y ` Thank you. – AlliDeacon May 10 '21 at 17:34

0 Answers0