批处理脚本压缩所有文件,但不父文件夹 [英] Batch script to zip all the files without the parent folder
问题描述
我想创建一个批处理文件,可以从我把在脚本文件夹进行压缩文件。这里是我的脚本:
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 ------------------
上面的脚本创建一个zip文件,像这样的结构,
The script above creates a zip file with a structure like this,
MyFolder
--subFolder1
--subFolder2
--file1.txt
--file2.doc
--file3.js
但我想要一个形成有一个像这样的结构的zip文件,而该文件夹父的(MyFolder文件)的
subFolder1
subFolder2
file1.txt
file2.doc
file3.js
谁能帮我解决这个问题?
Can anyone help me fix this?
请注意: 应用程序,我用的是WinRAR的的
note:application that I use is WinRar
推荐答案
更改的WinRAR.exe
调用行如下:
winrar.exe a -afzip -m5 -ed -pTest -r -ep1 c:\test.zip c:\MyFolder\*
的 -ep1
开关告诉归档从路径中排除的基本文件夹。但对于 C:\\ MyFolder文件
基本文件夹是 C:\\
,所以 MyFolder文件
仍然会被添加到档案文件。因此,你需要将路径更改为 C:\\ MyFolder文件\\ *
,为此,基文件夹是 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).
这篇关于批处理脚本压缩所有文件,但不父文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!