How to create zip file without path?


 
Thread Tools Search this Thread
Operating Systems Linux How to create zip file without path?
# 1  
Old 09-02-2009
How to create zip file without path?

Hello,

I have generated a PHP script that creates files needed for EPUB file.

I have a temp directory where these files are created into and then needs to be zipped. The directory structure is:

mimetype
content.opf
index.html
stylesheet.css
toc.ncx
META-INF
META-INF/container.xml

I use the following commands to create the EPUB file:

system ("zip -q0Xj $zipFile mimetype") ;
system ("zip -qXr9Dj $zipFile $myDir/mimetype $myDir/content.opf $myDir/index.html $myDir/stylesheet.css $myDir/toc.ncx $myDir/META-INF $myDir/META-INF/container.xml") ;

The problem is the the "j" option removes the path from all files, but I need the zip file to have all these files in the root of the zip except the META-INF directory and its file containes.xml must be at the root of the zip file.

So how can I create a zip file containing just these files and that one directory without the full path?

Thanks for your help!
# 2  
Old 09-02-2009
Quote:
Originally Posted by spaze
Hello,

I have generated a PHP script that creates files needed for EPUB file.

I have a temp directory where these files are created into and then needs to be zipped. The directory structure is:

mimetype
content.opf
index.html
stylesheet.css
toc.ncx
META-INF
META-INF/container.xml

I use the following commands to create the EPUB file:

system ("zip -q0Xj $zipFile mimetype") ;
system ("zip -qXr9Dj $zipFile $myDir/mimetype $myDir/content.opf $myDir/index.html $myDir/stylesheet.css $myDir/toc.ncx $myDir/META-INF $myDir/META-INF/container.xml") ;

The problem is the the "j" option removes the path from all files, but I need the zip file to have all these files in the root of the zip except the META-INF directory and its file containes.xml must be at the root of the zip file.

So how can I create a zip file containing just these files and that one directory without the full path?

Thanks for your help!
Specifying $myDir/META-INF and $myDir/META-INF $myDir/META-INF/container.xml both with the -r flag is redundant, as with -r it will traverse the directory tree and add everything inside.

You could call zip one more time, without the -j flag, to add that directory:
Code:
system ("zip -q0Xj $zipFile mimetype") ;
system ("zip -qXr9Dj $zipFile $myDir/mimetype $myDir/content.opf $myDir/index.html $myDir/stylesheet.css $myDir/toc.ncx");
system("zip -qXr9D $zipFile $myDir/META-INF");

# 3  
Old 09-03-2009
Quote:
Originally Posted by Corona688
You could call zip one more time, without the -j flag, to add that directory:
Code:
system ("zip -q0Xj $zipFile mimetype") ;
system ("zip -qXr9Dj $zipFile $myDir/mimetype $myDir/content.opf $myDir/index.html $myDir/stylesheet.css $myDir/toc.ncx");
system("zip -qXr9D $zipFile $myDir/META-INF");

This won't work as $myDir is in a form of "/var/www/customers/myaccount" so also this path will be included into the zip file.

So what I need is create a ZIP file of a remote diretory's contents so that also the META-INF folder will be included into the zip file but the parent folder structure is omitted.
# 4  
Old 09-03-2009
you could try to cd into $myDir before zipping.
as per man pages:
Quote:
By default, zip will store the full path (relative to the current path).
but this might vary depending on the system of course.
# 5  
Old 09-03-2009
Quote:
Originally Posted by Leppie
but this might vary depending on the system of course.
Personally, I doubt it. It's not like tar, where each platform rolls their own; zip is usually just info-zip everywhere you go. And it does go nearly everywhere.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Create zip file from root owned fstab

I want to zip up my fstab file for backup purposes. This does not work because of permission issues. cd /etc/ zip -u fstab.zip fstab Can I use this with zip? echo xxx | sudo -S or change fstab owner to me? (3 Replies)
Discussion started by: drew77
3 Replies

2. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

3. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

4. Linux

Unable to ZIP without path

We have been trying to zip a file with a Jenkins linux build server with a network path. We were trying use the different options for zip. We either get the full directory path with zip -r option or no directory with zip -j We need just the main path without the network path:example: /Documents... (2 Replies)
Discussion started by: Kenp11
2 Replies

5. Shell Programming and Scripting

Zip a file with path

zip /var/log/mylog.log mylog.1.log but its not working (5 Replies)
Discussion started by: Froob
5 Replies

6. Shell Programming and Scripting

create a zip file

Im fairly new to bash but I wanted to know about an idea I had to stream my file process these days. I modify .html, and .xml files and usually will take the files right click, create .zip, add files, rename, and cut the zip out of the folder and paste into another folder. I KNOW bash should be... (13 Replies)
Discussion started by: graphicsman
13 Replies

7. Shell Programming and Scripting

Find file and zip without including directory path

Does anyone know of a way to zip the resulting file from a find command? My approach below finds the file and zips the entire directory path, which is not what I need. After scanning the web, it seems to be much easier to perform gzip, but unfortunately the approach must use zip. find `$DIR`... (5 Replies)
Discussion started by: koeji
5 Replies

8. Linux

Create a dummy file even if the path is not exist

hi, i want to create a dummy file even if the path to that file is not exist as follows. suppose, in my working directory 2 files are there. and i create one more file which is exist as follows # pwd /home/satya # ls file1.txt file2.txt # echo dummy > /home/satya/file3.txt # ls... (3 Replies)
Discussion started by: snreddy_gopu
3 Replies

9. Shell Programming and Scripting

A shell script for create a a file in the respective path

Hello forum members, I have to create a out file in the current path./aaa/bbb/ccc/hhh. i am writing script below. ###script Begins##### #!/bin/ksh echo "Weclome" if then echo "Hello" rm -rf $aaa/bbb/ccc/hhh #clean the exsisting o/p file echo "no... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

10. Shell Programming and Scripting

Get zip path from unzip -l

I am listing the contents of a zip file and then grepping for a specific string ie: filename.a to get a line like: 309753 10-18-08 15:20 etc/filename.a The etc/filename.a is the path the file is at within the zip file...how might I capture this path as I want to use that path to unzip that... (2 Replies)
Discussion started by: phreezr
2 Replies
Login or Register to Ask a Question