Is there a way to add a folder to existing 7za archive? - 7zip

I have tried adding a new folder to an existing 7za archive using the following command from command prompt:
7za.exe a repo.zip \res\pub\newfolder newfolder
The above command added a folder to root of repo.zip. My intention was to add the new folder to location: \res\pub\folder inside repo.zip
Can anyone suggest or give me a correct command to add folder to a specific path of an archive?
Thanks,
Pradeep

Try to create a source location folder which you use for an update of your destination archive.
e.g.
7za.exe a "x:\destination_archive.7z" -up1q0r2x1y2z1w2 "c:\source_folder\*" -t7z -ms=off -mx1
I use this line of code every day to update a 7-zip archive. You need to adjust the '-u' parameter to your needs.

Related

Change permissions of file in CMake

I created a shell script using CMake just like this:
file(WRITE somescript.sh "echo foo!")
I want the user to be able to execute that script right away. For this, it would be nice to change the permissions of that file from within CMake.
Is there something like chmod u+x somescript.sh in CMake?
The problem with install is that existing files are not overwritten when the destination directory is equal to the source directory and when the files themselves did not change (CMake seems to compare timestamps). But nevermind, I found a working solution for everyone reading along:
Create the file as shown in the question but in a temporary folder ${CMAKE_BINARY_DIR}/tmp
Use file (COPY ${CMAKE_BINARY_DIR}/tmp/somescript.sh DESTINATION ${CMAKE_BINARY_DIR} FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
Remove the old file and the temporary directory: file(REMOVE_RECURSIVE ${CMAKE_BINARY_DIR}/tmp/)
You can do that in the istall command. Use this tags:
install(
FILES somescript.sh
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
DESTINATION /some/destination
)
In case you want to copy a binary I would use USE_SOURCE_PERMISSIONS

Add folder contents to .rar through console commands without adding folder itself

Here's a question:
I have a folder named Root and it contains some files and folders. Using Winrar console commands, I need to create an archive Root.rar that should contain entire file/folder structure of Root and SHOULDN'T contain Root folder itself.
For example:
On drive:
Root-
|-SomeFile
|-SomeFolder-
|-SomeOtherFile
In the Root.rar archive:
SomeFile
SomeFolder-
|-SomeOtherFile
I tried to do this:
"C:\Program Files\WinRAR\winrar.exe" a -r Root.rar Root\*
But it also adds the Root folder.
Then I tried this:
"C:\Program Files\WinRAR\winrar.exe" a -ep -r Root.rar Root\*
In this case winrar didn't add the Root folder, but it also didn't add any other folders, and instead of folder tree I've got a bunch of unstructured files. Is there any way of adding the folder structure, ignoring the Root?
Thank you!
Use -ep1 (exclude base folder names) instead of -ep (exclude paths from names)

How to use Windows Batch File to mass unzip files and saving them in specific folders?

I got the code to mass unzip from this link. But it unzips everything in the folder where the batchfile exists. I want it to unzip it to specific folders or its individual folders.
Note: my bz2 files are in various folders outside the folder where the batchfile exists.
Here's the script that i used :
for /R "C:\Users\victor\Desktop\MASTERS\color feret\disc 1\data\images" %%I in ("*.bz2")
do ("%ProgramFiles%\WinRAR\WinRAR.exe" x -y -o"%%~dpnI" "%%~fI")
Can someone enlighten me how to do it?
And also if possible, can anyone explain to me what are the arguments for? "x , -y -o %%dpnI " etc. Thanks
You do not need a batch file for this process at all. Start WinRAR, select all the archives you want to extract, click on Extract To in toolbar, select the base destination folder, check the option Extract archives to subfolders in Miscellaneous group and press button OK. That's it.
From a command line in a console window with current working directory being the directory containing all the *.bz2 files to extract:
"%ProgramFiles%\WinRAR\WinRar.exe" x -ad -y *.bz2 C:\Temp\
There is no need for a for loop as WinRAR supports wildcards for archive file names.
And with option -ad the archive file First.bz2 is extracted to folder C:\Temp\First, archive file Other.bz2 is extracted to C:\Temp\Other, and so on. With checking option Extract archives to subfolders in GUI, you use option -ad.
Help of WinRAR contains the page Switch -AD - append archive name to destination path. Click in menu Help on Help topics. On tab Contents open Command line mode and open Commands and Switches. Also text file Rar.txt in program files folder of WinRAR contains a description for command x and the options -ad and -y and all other commands and options for console version Rar.exe.
But if you want to use nevertheless a for loop and want to know what %%~dpnI and %%~fI mean, open a command prompt window, enter either help for or for /? and read.

How to use WinRAR through Batch?

I need some help with a batch file because I am stumped on WinRAR in Batch, as I haven't done/used it before.
Here is the TREE of my Folders including the batch file:
Each RAR file has the same Directory folder name("vegies" folder).
I would like to be able to extract/copy all folders/subfolders inside of each .rar from "Example/Program_Ex/vegie" back one directory into "Example/Program_Ex/vegies" (Dont forget the folder "vegies" already exists in each RAR which I cannot change as these automatically update themselves.)
So basically with a batch file I would like to:
extract "Example/Program_Ex/vegie/random.rar" to "Example/Program_Ex/vegies"
extract "Example/Program_Ex/vegie/random2.rar" to "Example/Program_Ex/vegies"
extract "Example/Program_Ex/vegie/random3.rar" to "Example/Program_Ex/vegies"
extract "Example/Program_Ex/vegie/random4.rar" to "Example/Program_Ex/vegies"
extract "Example/Program_Ex/vegie/random5.rar" to "Example/Program_Ex/vegies"
I also am trying to not specify a drive, more or less because the batch file will be in the correct folder instead using something such as "CD" or "PATH"?
I have looked at some examples around the web and on here of coarse, but I am still unsure the best way to go about this.
The closest example I can find would be this:
#echo off
set destinationRAR=destination_winrar_file
set source=source_folder_path
"C:\Program Files\WinRAR\WinRAR.exe" a -ep1 -esh -ibck -m0 -r -t %destinationRAR% %source%
(Above from http://fredy-invayne.blogspot.com.au/2013/05/example-winrar-batch-file.html)
Can anyone help give examples on how to implement my question please?
#echo off
for %%a in (
"%~dp0Example\Program_Ex\vegie\*.rar"
) do unrar x "%%~fa" -w "%~dp0Example\Program_Ex" -o+
For each file in the indicated path under the folder in where the batch file is stored, extract the content of the file indicating target folder and selecting that existing files must be overwritten.
You can extract all the archives with a single invocation of WinRAR:
"C:\Program Files\WinRAR\WinRAR.exe" x "%~dp0Program_Ex\vegie\random*.rar" "%~dp0Program_Ex\"
The last argument in the above command line specifies the target folder for all the archives. You may want to add the -o+ switch (must go just after x) to specify that all files should be overwritten:
"C:\Program Files\WinRAR\WinRAR.exe" x -o+ "%~dp0Program_Ex\vegie\random*.rar" "%~dp0Program_Ex\"
If you omit it, the archiver will ask you what to do with existing files, if any.

iexpress hard-coded extraction destination folder?

I'm using iexpress to make a self extracting executable. Is there a way I can hard-code an extraction destination folder (preferably into a temp folder somehwere) so as to not have the extraction pop up the "Please type the location where you want to place the extraced file." dialog?
There's no direct way to do this. (You can see my other answer for a longer explanation about it.)
The easiest solution is to make an IExpress archive that runs an "installation program", which is really just a batch file that copies the extracted files where they're needed.
In IExpress, you'd launch the batch file like: cmd /c persist.bat. And persist.bat looks something like:
#echo off
xcopy /y * "%temp%\persistent\"
del /f "%temp%\persistent\persist.bat"
(The last line is a nicety to hide the fact that you used this batch file to copy the extracted archive.)
Yes, this is possible through the use of an .INF file when you select "Extract files and run an installation command". You must set the .INF file as your Install Program and under the DestinationDirs section you would put the path to the directory you want the files to go to. Here is an example of an .INF file:
[version]
signature="$CHICAGO$"
[DefaultInstall]
CopyFiles=install.files
[DestinationDirs]
install.files=-1,"C:\Program Files\MyCustomDir"
[install.files]
MyFile1.txt
MyFile2.bmp
So this sample shows that the installer will install to C:\Program Files\MyCustomDir. The files under the install.files should list all the files you want to copy to that folder. They must be included in your installer when you are selecting the files to add.

Resources