Skip to content
Advertisement

Zip Junk Paths Option Not Working

I have a bit of an odd one that I can’t seem to figure out.

Here’s the setup. I am downloading a bunch of files given to a script via array. The files are not necessarily in the same folder, so I don’t think just using cd to change directory and then add the files I want is going to work.

I have added -j to my shell command in order to not include the directories, and it worked… kinda. Now I have all the files in the top level of the zip, but it’s also included the directories and duplicate versions of the files in the appropriate directories.

Any thoughts?

Edit: code added.

I have an array of files like this:

JavaScript

So what I’d like is to have all the images in the root of the zip, but what I’m getting is both directories and junked directories in one zip:

JavaScript

My code is quite simple, I’m using -j to strip out the directory and passing an array of files to zip. If I remove the -j, it only includes a single copy of the files, although in the folders, so I know the issue is not my array doubling up on the files.

JavaScript

Edit Solved. Kind of.

For some reason when I placed the -j at the end of the command line, it works as expected. Unsure why that would matter, but it fixed it. Here’s what worked.

JavaScript

Advertisement

Answer

You can use a combination of find and zip together. Run the above command at the same level as the individual folders.

JavaScript

The find command lists the jpg files from he current path and with the -@ option in zip is to read from stdin which the previous command produces. And the -jq flag for junk paths.

With the above command, I was able to achieve the structure as you intended. Use unzip -l to list the files under the archive without extraction.

JavaScript

The above simulation of mine is for your original input, when you had 4 images in total.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement