I wanted to create a batch file that can make a zip file from a folder that I put in the script. Here's my script:
@REM ------- BEGIN xpi.bat ----------------
@setlocal
@echo off
set path="C:\Program Files\WinRAR\";%path%
winrar.exe a -afzip -m5 -ed -pTest -r c:\test.zip c:\MyFolder
REM ------- END xpi.bat ------------------
The script above creates a zip file with a structure like this,
MyFolder
--subFolder1
--subFolder2
--file1.txt
--file2.doc
--file3.js
But what I want the zip file that is formed has a structure like the this, without the folder parent (MyFolder),
subFolder1
subFolder2
file1.txt
file2.doc
file3.js
Can anyone help me fix this?
note:application that I use is WinRar
Locate the file or folder that you want to zip. Press and hold (or right-click) the file or folder, select (or point to) Send to, and then select Compressed (zipped) folder. A new zipped folder with the same name is created in the same location.
Syntax : $zip –m filename.zip file.txt 4. -r Option: To zip a directory recursively, use the -r option with the zip command and it will recursively zips the files in a directory. This option helps you to zip all the files present in the specified directory.
Right-click on the file or folder. To place multiple files into a zip folder, select all of the files while hitting the Ctrl button. Then, right-click on one of the files, move your cursor over the “Send to” option and select “Compressed (zipped) folder”.
Change the winrar.exe
invocation line as follows:
winrar.exe a -afzip -m5 -ed -pTest -r -ep1 c:\test.zip c:\MyFolder\*
The -ep1
switch tells the archiver to exclude the base folder from the paths. But for C:\MyFolder
the base folder is C:\
, so MyFolder
will still be added to the archive. Therefore you need to change the path to c:\MyFolder\*
, for which the base folder is c:\MyFolder
(and it will be excluded).
You can use this batch file for creating rar without parent folder.
SET WINRAR="C:\Program Files\WinRAR"
%WINRAR%\WinRAR.exe a -ep1 "D:\Archive\Test.rar" "D:\Projects\Test"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With