批处理脚本来压缩所有文件而不包含父文件夹
我想创建一个批处理文件,可以从我放入脚本中的文件夹生成 zip 文件。这是我的脚本:
@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文件,
MyFolder
--subFolder1
--subFolder2
--file1.txt
--file2.doc
--file3.js
但是我希望形成的zip文件具有这样的结构,没有文件夹父(MyFolder),
subFolder1
subFolder2
file1.txt
file2.doc
file3.js
可以有人帮我解决这个问题吗?
注意:我使用的应用程序是 WinRar
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
按如下所示更改
winrar.exe
调用行:-ep1
开关告诉归档程序从路径中排除基本文件夹。但对于C:\MyFolder
来说,基本文件夹是C:\
,因此MyFolder
仍会添加到存档中。因此,您需要将路径更改为c:\MyFolder\*
,其基本文件夹为c:\MyFolder
(并且它将被排除)。Change the
winrar.exe
invocation line as follows:The
-ep1
switch tells the archiver to exclude the base folder from the paths. But forC:\MyFolder
the base folder isC:\
, soMyFolder
will still be added to the archive. Therefore you need to change the path toc:\MyFolder\*
, for which the base folder isc:\MyFolder
(and it will be excluded).您可以使用此批处理文件来创建没有父文件夹的 rar。
SET WINRAR="C:\Program Files\WinRAR"
%WINRAR%\WinRAR.exe a -ep1 "D:\Archive\Test.rar" "D:\Projects\Test"
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"
现在我按照您的要求列出
我在桌面上创建了 MyFolder,其中包含 5 个文件
例如,正如您所给出的
,现在您查询的是压缩 MyFolder 中的所有内容,那么第一步是
导航到位于桌面中的文件夹路径,所以首先我将
找到我的桌面。
注意:(我的用户名将与您不同,希望您了解基本的 Windows 内容)
其中,
winrar
是压缩命令a
是参数MyFolder
为 zip 命名。*.*
表示压缩所有文件Now I'm listing as per your requirement
I've MyFolder Created on my Desktop which contains 5 files
for example below as you've given
Now you query is to zip all the contents within MyFolder then the first step is
to navigate to that folder path which is located in Desktop so first i will
locate to my desktop.
Note:(My username will be different from you hope you know the basic windows stuff)
where,
winrar
is command to zipa
is argumentMyFolder
to give name to zip.*.*
means zip all the files