View Single Post
Old September 16th, 2013, 02:37 PM   #919 (permalink)
palmtree5
Senior Member
 
palmtree5's Avatar
 
Join Date: May 2012
Location: USA
Gender: Male
Posts: 2,744
 
Device(s): HTC One SV, Samsung Galaxy Prevail (retired), Nexus 7 (Gen 1)
Carrier: Boost Mobile

Thanks: 1,655
Thanked 1,462 Times in 754 Posts
Default

Quote:
Originally Posted by MoodyBlues View Post
I just slapped something together, but I'm not 100% sure it's exactly what you're after.

From your snippet, it looks like you want to hard-code the working directory, then at runtime you want to manually enter the name of a subdirectory to zip, correct? Is that actually how you want it? If so...ignore the following!

This--as it stands right now--has nothing hard-coded, meaning it can be run in any directory, and it automatically finds all of its subdirectories, and zips each one as its own subdirectory-named zip file in its own subdirectory. Obviously, this can be tweaked as far as location of the zipped files, whether or not you enter a directory/subdirectory name, and so on:

Code:
#!/bin/bash
for SUBDIR in `ls -d1 */` 
do ZIPFILE=`basename $SUBDIR`
zip -r $SUBDIR$ZIPFILE.zip $SUBDIR
done
Any questions about what's doing what, just ask.
The way the directories are is my work directory has subdirectories for each section. In those subdirectories are the directories that need to be zipped in such a way that each of those directories is its own zip file. What you gave me works if I was trying to include the entire section in one zip.
__________________
Find a post helpful? Hit
See spam or something offensive? Hit
New to the site? Site Rules/Guidelines and Introductions
Not a member yet but want to join? Join here!
Let's cure cancer with our phones
palmtree5 is offline  
Reply With Quote