0

I have about 300 zip file and i want to extract their image in folder where the zip is exist and some of them have 2 or 3 pictures then change their name to zip's name in zip's name folder

Before:

C:\zips\Myfile.Zip\word\media\image.Png
C:\zips\Myfile.Zip\word\media\image1.Png
C:\zips\hdh\Product.Zip\word\media\image.png
C:\zips\hdh\Product.Zip\word\media\image1.png

After:

C:\zips\Myfile\myfile.Png
C:\Myfile\myfile1.png
C:\zips\hdh\Product\product.Png
C:\zips\hdh\Product\product1.png

My code to extract all the image files in zip's folder name:

for /R %%I in ("*. Zip") do ( 7z e "%%~fI" "word/media/*" -o"%%~dpnI" )

My batch code to rename all image's name to direction where they are, it works just for the zips that have just one image, if a zip file have more than one picture, it just changes a image file not other images and i want to change other images to "folder's name"1.png and.... :

For /r %%F in (*.jpeg) do @for %%A in ("%%F\°°") do ren "%%F" "%%~nxA.jpeg"

For /r %%F in (*.png) do @for %%A in ("%%F\°°") do ren "%%F" "%%~nxA.png"

Mhwmd
  • 71
  • 8
  • this can be done with [zipjs.bat](https://stackoverflow.com/a/28043695/388389) without need to install third party binaries. If you give me few minutes I can prepare a script. – npocmaka May 15 '18 at 13:05
  • 2
    What have you tried so far, which unzipper do you want to use? [SO] isn't a script writing service, show your own coding effort by [editing](https://stackoverflow.com/posts/50350289/edit) your question. –  May 15 '18 at 13:08
  • What have you tried so far, where are you stuck? – aschipfl May 15 '18 at 13:58
  • Just download an appropriate executable to do the unzipping. `7za.exe` a free tool from the famous `7-Zip` people doesn't need installing and a basic command like this `7za x *.zip -o*` should extract all `.zip` files in a directory outputted to directories with names matching theirs. – Compo May 15 '18 at 18:03
  • 1
    @Mhwmd, please delete your answer adding it's content as a comment in the appropriate comment area. – Compo May 15 '18 at 20:32

1 Answers1

0

download the zipjs.bat in the same directory as this script:

:::::::::::

@echo off

set "zipDir=C:\zips\"
set "inZipPath=\word\media\"
set "picFormats=bmp png jpg gif tiff bpm"

break>"pic.list"
for %%a in ("%zipDir%\*.zip") do (

    rem echo %%a
    (call zipjs.bat list -source "%%~fa" -flat yes | find /i "%inZipPath%" | findstr /i /e "%picFormats%")>>"pic.list"
)

setlocal enableDelayedExpansion

    set "prevZN="
    set "counter=1"
    for /f "usebackq tokens=* delims=" %%f in ("pic.list") do (
        set "full_path=%%f"
        set "tfp=!full_path:\word\media\=?!" 
        for /f "tokens=1,2 delims=?" %%a in ("!tfp!") do (
            echo %%a ### %%b
            for %%# in ("%%a") do set "zipname=%%~n#"
            for %%# in ("%%a") do set "zipdir=%%~dp#"
            for %%# in ("%%b") do set "filename=%%~b"
            for %%# in ("%%b") do set "fileext=%%~xb"
        )

        if "!zipname!" NEQ "!prevZN!" (
            set counter=1
            set prevZN=!zipname!
        ) else (
            set /a counter=counter+1
        )
        call zipjs.bat unZipItem -source "!full_path!" -destination "!zipdir!\temp" -keep yes -force yes
        ren "!zipdir!\temp\!filename!" "!zipname!!counter!!fileext!"
        move "!zipdir!\temp\!zipname!!counter!!fileext!" "!zipdir!"
    )

endlocal
npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • It doesn't work for me this code just extract one of zip files then extract 1 png to zip's name1. Png but i need a code to find all images in folders and subfolders then change their name to folder where they are, some of extracted zips have 2 or 3 images that should be change %%~nxA_number.png – Mhwmd May 16 '18 at 05:43
  • @Mhwmd does it create a `pic.list` file where the image files are listed? – npocmaka May 16 '18 at 10:24
  • Yes it did but it creates the pic. List in folder where i put the bat file not in zips folder – Mhwmd May 16 '18 at 16:49
  • Like before i don't see any changes – Mhwmd May 17 '18 at 11:55
  • @Mhwmd - are the pictures allays in the `\word\media\` folder? – npocmaka May 17 '18 at 12:05