1

My problem is this

I have an extensive collection of pictures spanning several sub-folders (I'm talking of several hundred of folders, not a few), under a main folder, as example:

Birthdays

Mom

Older Sister

Younger Brother

And so on.

I found a couple of batch files which automates the creation of zip files (with the same name of the Sub-folder) of every folder under the main folder and then move those zip files to the same-name folder, to use in a picture viewer, however, all the pics are still inside every sub-folder, and manually deleting thousands of pics is a chore

What I'm looking for is a batch script that deletes all the pics inside the sub-folders, minus the zip file and a single 0000.jpg / png / bmp file, that will act as a cover for the folder

I found this code online:

for /f %F in ('dir /b /a-d ^| findstr /vile ".filetypeA .filetypeB"') do del "%F"

Which apparently do what I'm looking for, however it need to be done for every folder, and that defeats the purpose of the automation I'm looking for

Any help will be appreciated

EDIT:

Clarifying on this issue: I only need the *.zip file and the 0000.JPG / PNG / BMP file, and nothing else

The 0000.* File will be used by an Android app as the cover of the folder (an specific app, like a comic viewer), Windows don't needs this in any sort of way, so the batch only needs to skip those files and delete the rest

1
  • 1
    I am not 100% understanding. Are you able to use a simple file mask to do the delete? del has a recursive option.. as in del *.filetypeA /s .. I am mostly sure I don't understand. Commented Feb 13, 2023 at 5:31

1 Answer 1

1

Edit:

Clarifying on this issue:
I only need the *.zip file and the 0000.JPG // PNG // BMP file, and nothing else.

The 0000. File will be used by an Android app as the cover of the folder
(an specific app, like a comic viewer), Windows don't needs this in any sort of
way, so the batch only needs to skip those files and delete the rest


@echo off && Setlocal EnableDelayedExpansion

cd /d "D:\The\Full\Path\To\Your\Main Folder"
set "_skipt=findstr /live "0000\.jpg 0000\.png 0000\.bmp \.zip"

for /d /r %%i in =;(*);= do ;(cd /d "%%~dpnxi" && for /f delims^= %%? in =;(
    '2^>nul dir /b /a:-d ^| 2^>nul !_skipt! ');= do del /q /a /f "%%~f?" );=
   
endlocal


// Previous version in another understanding //


 @echo off && Setlocal EnableDelayedExpansion

cd /d "D:\The\Full\Path\To\Folder"
set "_fdel=*.jpeg *.jpg *.png *.gif *.tiff *.psd *.pdf *.eps *.ai *.indd *.raw"

for /d /r %%i in =;(*)do ;( cd /d "%%~fi" && for /f delims^= %%G in =;('
    2^>nul %__AppDir__%where.exe ".:%%~nxi.zip" ".:Desktop.ini"'
   )do =;(
        if "%%~nxi.zip" == "%%~nxG" =;( 
               call %:^) "%%~nxG" zip
           )=; else if "%%~xG" == ".ini" =;( 
               for /f tokens^=2delims^=^= %%X in =;('
                    2^>nul findstr /i "Logo=" ^<".\%%~nxG"')do call %:^) "%%~nxX" img
               for /f delims^= %%? in ('2^>nul dir /b /a:-d %_fdel% ^| 2^>nul findstr /vei "!_zip! !_img!"'
                   );= do echo\del /q /a /f "%%~dpnx?"
           );=
       );=
    for %%v in (var,img,zip,rm\)do set "_%%~v=" <nul
   );=
       
%:^)
if "%~1" == "" =;( 
    endlocal && goto :eOf
   );= else set "_var=%~1"
   
set "_rm\=%_var:*\=" & set "_var=%"
set "_%~2=!_var: =/\ !"
set "_%~2=!_%~2:.=\.!" & exit /b

  • The task requires more than a for loop and other commands in one line to run, excluding its target files but preserving a .zip file if present in the folder, preserving a cover file of each folder if defined, and also another file whose extension can be .jpg, .png or .bmp.

About:
minus the zip file and a single 0000.jpg / png / bmp file, that will act as a
cover for the folder

  • Filtering and/or omitting the .zip file in a loop for each folder is something simple, trivial, but with regard to the image assigned to the cover of the folder, where only a single file will be kept, whether it be a .jpg, a png or a bmp, this will make you keep an additional file (desktop.ini) in the folder, and this file is what has the name settings of the cover image that was assigned to the folder itself.

  • An alternative to also delete the desktop.ini file (hidden) would be to consult the links below, which guide you to rename the desired file to Folder.jpg, and if that were the case, with specific attention, that would be another question/answer:

How do i change the photo that appears on the front of photo folders?

Add a picture to your folder and name it folder.jpg. That picture will now appear on the folder icon.


For what was currently asked, I suggest a batch that will execute the actions as I understand it in the current version of your question

  1. List files recursively;

  2. In each folder check the existence of some (unique) .zip file with the same name as the folder currently in loop, and if confirmed, keep/don't delete it;

  3. Check for existence of Desktop.ini file and get/read from it the name of the file currently being used as cover of the current folder in loop and with that done, use it to keep/don't delete the file defined as cover of the folder;


Obs 1.: The current batch assumes that the files being used to cover the folders are unique and are each in their own folder being used.

Obs 2.: The command that effectively deletes is "neutralized" in the echo\ del ..., so that it is possible to verify that commands and the files to be kept/deleted in the respective commands, are correct.


Some further reading:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .