Script to Add files to a Zip archive with out unzipping it !!
Hii
I need to add files to an already existing Zip archive with out unzipping it. Without unzipping it because the Zip archive is very large for which space won't be enough to contain both the archive and actual files. but where as files to be added are very small. I am thinking of a script to do this automatically when ever files are ready to be added. Does this command work ? $> zip -g .... Its something like adding patches to an already existing module. |
Quote:
Code:
zip -g mylargezipfile.zip filetoadd.txt |
Quote:
good .. but the point is.. its something like this mylargezipfile.zip contains a folder say Module |-------Folder one |----Folder two Now say, i have to add "filetoadd.txt" into Folder two... Sometimes we may need to add a folder itself to the zip archive.. Then? |
Then create your file to add in a folder of the proper name, and add it. If your folder names contain spaces, don't forget to quote them.
|
Quote:
zip -g mylargezipfile.zip filetoadd.txt see In "mylargezipfile.zip" the structure is like this. Module ...|------- Folder1 .......|---- Folder2 ................|-no file. After running the script it should be like this in the zip itself Module |----- Folder1 ...|-----Folder2 ............|---- filetoadd.txt This should be the structure inside the Zip file. |
Quote:
But, how to do that with the command.. i mean EDIT this.. zip -g mylargezipfile.zip filetoadd.txt see In "mylargezipfile.zip" the structure is like this. Module ...|------- Folder1 .......|---- Folder2 ................|-no file. After running the script it should be like this in the zip itself Module |----- Folder1 ...|-----Folder2 ............|---- filetoadd.txt This should be the structure inside the Zip file. |
Quote:
But, how to do that with the command.. i mean EDIT this.. zip -g mylargezipfile.zip filetoadd.txt see In "mylargezipfile.zip" the structure is like this. Module ...|------- Folder1 .......|---- Folder2 ................|-no file. After running the script it should be like this in the zip itself Module |----- Folder1 ...|-----Folder2 ............|---- filetoadd.txt This should be the structure inside the Zip file. I hope you got my point. |
Is there an echo in here?
ECHO Echo echo e... .... So there is. But back to the question. Make a directory and put the file in there, and then make the command referencing the path to the file (we call them directories on unix-like OSes - "folder" is a word from the Windows world). i.e. Code:
mkdir "folder one" |
Quote:
Anyway what happens if folder1 already contains some files in it and i have to add this new file [say, new patch] to it.. I didnt get, why we are creating a directory again ?? and add this file. Directory exists already inside the zip, right?? |
Are you going to add a new condition each time I reply? How about you explain the exact situation first?
|
Quote:
Ok here is the situation... All modules in my project are stored as zip files.. there are many such modules.. Now each and every module will be updated based on user requirements... so we have to develop a patch to it and add to those zip files.. Since zip files are big we cant unzip it everytime. And each module contains some hundreds of directories and sub directories and files in them. Now, based on the requirement I have to update that particular sub-directory with the patch. Directories can be like this. ModuleXX ...|---DBConn ...|---SourceFiles ..........|--GUI.c ..........|--Random.c ...|---Patches Something like that.. Everytime a new patch is developed it has to be automatically updated i.e added to say "patches" or "DBConn" directory. Whats ur idea on this ?? how to do ? |
You can create a temporary directory, change into it, create the sub-directory you want with the new file and then add it. You can specify the .zip file by its full path, so you don't have to move it or anything like that.
For example. Say your .zip file is: /home/matthew/zipfiles/mybigfile.zip and you want to add /home/matthew/patches/mynewpatch to the patches sub-directory inside mybigfile.zip, you might write a little script which takes the full path of the .zip file and the patch file and the sub-directory name: Code:
#!/bin/bash |
Everything seems fine !! I develop the script soon and let u know the result..
Thanks for the solution Matthew.. |
All times are GMT -5. The time now is 02:49 AM. |