I am using the below command in Terminal, found here from this answer by @Theophrastus to zip all *.html and *.js files with the same name, while retaining the name of those paired files.

How to zip files with same name but different extension?

for Q in *;do H=${Q%%.*};zip "${H}.zip" "$Q";done

I would like to also have a folder called images included in the zip file, but do not understand what the command above does.

Structure is


|-   images


Once completed the zip files should have the same name they started with, which is the name that the html and js files share.

  • check out the {} formatting button to format code separately; it makes it much more readable. Thanks! – Jeff Schaller Feb 11 '19 at 15:25
  • 1
    Try for file in *.zip ; do zip -ur "$file" images ; done – Bodo Feb 11 '19 at 15:33
  • I'm being misled by the introduction in the question; is there anything about matching or paired filenames that are important to you? – Jeff Schaller Feb 11 '19 at 15:56
  • Just that the files being zipped initially are an html file that has a js file with the same name. – Susan Forman Feb 11 '19 at 15:57
  • Bodo's comment would fix the zip files after-the-fact; are you interested in creating them with the images directory there initially? – Jeff Schaller Feb 11 '19 at 15:59

You cannot specify wildcards as the zip file argument for the zip command because the shell would replace this with multiple file names. Instead you can use a loop to process multiple zip files one by one.

for file in *.zip
    zip -ur "$file" images

or in one line

for file in *.zip ; do zip -ur "$file" images ; done
| improve this answer | |
  • or initially with for Q in *;do H=${Q%%.*};zip "${H}.zip" images "$Q";done – Jeff Schaller Feb 11 '19 at 16:01
  • That also works, Jeff Schaller. The way that Animate CC publishes canvas files, is that there is only an images folder, if there are bitmaps. – Susan Forman Feb 11 '19 at 16:20
  • Actually I spoke too soon. for Q in ;do H=${Q%%.};zip "${H}.zip" images "$Q";done moves the html and js file to a newly created images folder in the zip, breaking the path to the bitmap in the images folder. – Susan Forman Mar 7 '19 at 15:12
  • @SusanForman Please edit your question to show an example which files and folders you originally have, what should be the contents of the ZIP file(s) and how the ZIP file(s) should be named. – Bodo Mar 11 '19 at 13:35
  • Done. Thanks for the solution Bodo. Being a 2 part command in Terminal is actually ideal, as Animate CC only creates an image folder if there are imported bitmaps. All vector Animate content, no images folder. – Susan Forman Mar 12 '19 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.