Script package for zip all files without parent folder

I wanted to create a batch file that could make a zip file from a folder placed in a script. Here is my script:

@REM ------- BEGIN xpi.bat ---------------- @setlocal @echo off set path="C:\Program Files\WinRAR\";%path% winrar.exe a -afzip -m5 -ed -pTest -rc:\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 that I want the generated zip file to have a structure like this, without a parent folder (MyFolder),

 subFolder1 subFolder2 file1.txt file2.doc file3.js 

Can someone help me fix this?

note: the application i use is winrar

+6
source share
4 answers

Modify the winrar.exe call winrar.exe 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 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).

+4
source

You can use this batch file to create rar without a parent folder.

SET WINRAR = "C: \ Program Files \ WinRAR"

% WINRAR% \ WinRAR.exe a -ep1 "D: \ Archive \ Test.rar" "D: \ Projects \ Test"

+1
source

Now I list according to your requirement. I have a MyFolder created on my desktop that contains 5 files, for example below, as you indicated

 MyFolder --subFolder1 --subFolder2 --file1.txt --file2.doc --file3.js 

Now you request zip all the contents in MyFolder, then the first step is to go to this path to the folder that is on the desktop, so first I search on my desktop.

Note: (My username will be different from you, you hope you know the basic Windows materials)

 1.C:\Documents and Settings\ishwar\Desktop\MyFolder>set path="c:\ProgramFiles \WinRAR";%path% -- Set the path (note if you are doing using commands from cmd prompt you need to do this every time when you open cmd newly if you are creating batch file then OK) 2. C:\Documents and Settings\ishwar>cd Desktop 3. C:\Documents and Settings\ishwar\Desktop>cd MyFolder -- change directory to the folder in which all the files are stored. 4. C:\Documents and Settings\ishwar\Desktop\MyFolder>winrar a MyFolder *.* -- this command will zip all the contents and will create MyFolder.rar file within MyFolder. 5. You are done. 

Where

winrar - zip command

a is an argument

MyFolder to specify a name in zip.

*.* means zip of all files

enter image description here

0
source
 @REM ------- BEGIN demo.cmd ---------------- @setlocal @echo off set path="C:\Program Files\WinRAR\";%path% for /F %%i in ('dir /s/b *.rar') do call :do_extract "%%i" goto :eof :do_extract echo %1 mkdir %~1.extracted pushd %~1.extracted unrar e %1 popd REM ------- END demo.cmd ------------------ 
0
source

Source: https://habr.com/ru/post/892769/


All Articles