9

我想创建一个批处理文件,它可以从我放入脚本的文件夹中制作一个 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

4

4 回答 4

8

更改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(它将被排除在外)。

于 2011-07-15T07:32:11.527 回答
1

您可以使用此批处理文件来创建没有父文件夹的 rar。

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

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

于 2012-08-06T06:16:25.113 回答
0

现在我根据您的要求列出我在我的桌面上创建的 MyFolder,其中包含 5 个文件,例如您给出的下面

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

现在您查询的是压缩 MyFolder 中的所有内容,然后第一步是导航到位于桌面的文件夹路径,因此首先我将定位到我的桌面。

注意:(我的用户名会和你不一样希望你知道基本的windows东西)

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.

在哪里,

winrar是压缩命令

a是论据

MyFolder为 zip 命名。

*.*意味着压缩所有文件

在此处输入图像描述

于 2011-07-14T16:50:18.080 回答
0
@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 ------------------
于 2012-07-06T10:44:44.383 回答