samedi 30 mai 2020

Test IF file exist, del this local file

To Mofi, much thanks for answering my other question that provided some used code below. Asking another question to all, same vein:

Background: On occasion I choose to run "aGallery-dl.bat" in a given folder (just one in each of 100's of folders). It first deletes Folder.jpg then renames Folder2.jpg to Folder.jpg. This has the effect of the red X being replaced by the yellow ! when viewing the folder in File Explorer parent folder. Secondly, it calls "gallery-dl.exe." I use going from red to yellow to let me know I've run "aGallery-dl.bat" at least once. If "aGallery-dl.bat" completes successfully, it finally deletes the Folder.jpg (currently yellow !), and now the representative contents of the folder (usually DeviantArt .jpg's) are visible. All is well.

rem @echo off
del .\Folder.jpg
ren .\Folder2.jpg Folder.jpg
FOR /F %%i IN ('cd') DO set FOLDER=%%~nxi
"C:\Program Files (x86)\gallery-dl\gallery-dl.exe" -d "U:\11Web\gallery-dl" --download-archive ".\aGDB.sqlite3" "https://www.deviantart.com/"%FOLDER%"/gallery/all"
del .\Folder.jpg

Problem: Restating, Gallery-dl.bat is in each of 100's of folders. On occasion, I run one of these from within it's local folder. Line 5, if the call to the Web site is successful, gallery-dl.exe creates zzzGDB.sqlite3 within the local folder.

In the previous code, when aGallery-dl.bat completed, it would just delete the Folder.jpg. This assumes the call to the Web page was successful. On rare occasion, the call to the Web page will fail for any number of reasons, though at close (due to that final "del .\Folder.jpg"), it will still delete Folder.jpg.

If zzzGDB.sqlite3 was not created/not present, I need the Folder.jpg (yellow !) to remain.

So, in the below code (line 6, now blank), I've lopped off the final "del .\Folder.jpg" and am trying to plug-in the provided code beginning at line 7, inserting a test for zzzGDB.sqlite. If found, "del .\Folder.jpg". If not found, no action is taken against Folder.jpg (it remains). (The "rem" statement at the very bottom is just acting as a placeholder for my own knowledge.)

rem @echo off
del .\Folder.jpg
ren .\Folder2.jpg Folder.jpg
FOR /F %%i IN ('cd') DO set FOLDER=%%~nxi
"C:\Program Files (x86)\gallery-dl\gallery-dl.exe" -d "U:\11Web\gallery-dl" --download-archive ".\zzzGDB.sqlite3" "https://www.deviantart.com/"%FOLDER%"/gallery/all"

setlocal EnableExtensions DisableDelayedExpansion
for /D %%I in ("U:\11Web\gallery-dl\deviantart\*") do (
    if exist "%%I\zzzGDB.sqlite3" (
        del "%%I\Folder.jpg"
    )
rem 
)
endlocal

Note: Currently, the modified code goes back thru every single folder within "U:\11Web\gallery-dl\deviantart*". This action should be reserved only to the local folder. I'm guessing the below is the issue.

for /D %%I in ("U:\11Web\gallery-dl\deviantart\*")

I don't know how to remove it and still implement everything after "do"???

do (
if exist ".\zzzGDB.sqlite3" (
    del ".\Folder.jpg"
)
rem 
)

Aucun commentaire:

Enregistrer un commentaire