how to zip and unzip using command prompt only

Anonymous
2023-03-26T12:42:10+00:00

hi there,
i am trying to zip 5 photos, using cmd command prompt.
the prompt i am using is: tar -a -c -f compressed.zip *jpg
and this works perfectly fine as all the files are getting zipped in a folder called compressed.zip

but the issue is all files are getting compressed in one folder(compressed.zip)

I want these photos to be zipped in each out their folders.
for example 5 different unique zip folders for each of the 5 photos.

viceversa

and to unzip i am using : tar -xf compressed zip.
which works fine too, but i would like unzip 5 zipped folders in 5 unquie folders

Any help here please

Akash

Windows for home | Windows 11 | Files, folders, and storage

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Anonymous
    2023-03-26T13:05:11+00:00

    Hi akash0000

    To compress try this syntax:

    for %i in (*.jpg) do tar -a -c -f %~ni.zip %i

    To unzip you have to create a list of desired files to process (list.txt), then:

    for /f %i in (list.txt) do tar -xf %i.zip

    4 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2023-03-26T13:10:53+00:00

    hi there,
    this is really helpful

    it works for me

    now can i do it for folder.
    For example, i have 5 folders
    i want to zip these 5 folders with unique zip files
    for example: 5 folders will have 5 .zip files

    And vice versa;
    if i have 5 zip files, i want to unzip them in 5 different folders of their own

    0 comments No comments
  3. Anonymous
    2023-03-26T13:41:25+00:00

    The first command changes as below:

    for %i in (*.jpg) do tar -a -c -f %~ni%~ni.zip %i

    With the second commands you need to change the list.txt file

    0 comments No comments
  4. Anonymous
    2023-03-26T18:29:35+00:00

    hi there,
    thank you for your help there.

    I am using this instead in cmd, which is more precise

    zip single jpg for %i in (*.jpg) do tar -a -c -f "%~ni.zip" "%i"
    unzip single jpg for %i in (*.zip) do tar -xf "%i"
    zip mutiple files for /d %i in (*.*) do tar -a -c -f "%i.zip" "%i"
    unzip multiple files for /d %i in (*.zip) do tar -xf "%i"

    the prompt you gave me was giving me errors and was a bit confusing

    akash

    3 people found this answer helpful.
    0 comments No comments
  5. Anonymous
    2023-03-26T20:22:45+00:00

    You're most welcome Akash.

    Have a good day/night.

    0 comments No comments