nemo
nemo

Reputation: 1584

"zip -m" Don't Delete Directory if it Becomes Empty

I need to move the contents of a directory into an archive and I was delighted to find that the "-m" option does exactly that. (Of course, I'm using it with the "-T" option. :) )

But unfortunately, if the directory becomes after the zip operation, the directory itself is removed. I don not want this to happen, but can't find any option that behaves like this.

Do you guys have any ideas how I can get this behavior?

Here's my actual (obfuscated) command I'm using in my shell script:

zip -qrTmy $archive_name $files_dir

Upvotes: 1

Views: 1552

Answers (1)

Hai Vu
Hai Vu

Reputation: 40688

Unless your directory contains sub directories, it is not hard to recreate it after a zip/move:

zip -qrTmy $archive_name $files_dir
mkdir $files_dir

If the directory contains sub directories, then we need to duplicate that directory structure to a temporary name, perform a zip/move, rename the structure back. I'm still working on how to implement this idea. If I know a solution, I'll update this post.

UPDATE

If the directory contains sub directories:

find $files_dir -type d -exec mkdir temp_{} \; # Duplicate the dir structure
zip -qrTmy $archive_name $files_dir
mv temp_$files_dir $files_dir                  # Restore the dir structure

Upvotes: 1

Related Questions