只需使用 WinRAR 命令行批量压缩 1 个文件夹? [英] Simply compress 1 folder in batch with WinRAR command line?

查看:55
本文介绍了只需使用 WinRAR 命令行批量压缩 1 个文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 WinRAR 命令行 (C:Program FilesWinRAR ar.exe),我想要做的就是压缩单个文件夹 (C:Users\%username%desktopsomeFolder) 并可能更改创建的 .zip 文件的名称.我只试过rar.exe a"C:Users\%username%desktopsomeFile",它可以工作,但它压缩了另一个文件夹(不是我放的那个).

我做错了什么?

您能否也提供解释(也许告诉我递归是什么,因为我不熟悉它)?

谢谢

解决方案

使用其中一个

"%ProgramFiles%WinRARRar.exe" a -ep1 -idq -r -y "带路径的 RAR 文件名称" "%UserProfile%DesktopsomeFolder"

"%ProgramFiles%WinRARRar.exe" a -ep1 -idq -r -y "带路径的 RAR 文件名称" "%UserProfile%DesktopsomeFolder"

在命令a(添加到存档)和开关后使用指定名称创建RAR存档文件

  • -idq ... 启用安静模式以仅显示错误消息,
  • -ep1 ... 从指定的文件/文件夹名称中排除基本目录,
  • -r ... 递归归档/压缩所有文件和子目录,
  • -y ... 假设所有查询都.

文件夹 someFolder 包含在存档中,第一个命令行末尾没有反斜杠.

文件夹someFolder 不包含在存档中,只包含该文件夹的文件和子目录,第二个命令行末尾有反斜杠.

换句话说,选项 -ep1 导致在将文件或文件夹添加到存档时省略从路径到最后一个反斜杠的所有内容或文件夹名称,这解释了添加文件夹的不同之处或在命令行指定的末尾有反冲.

递归 表示不仅添加指定文件夹中的文件,还添加所有子文件夹和所有子文件夹中的所有文件.

所以 RAR 必须首先在指定文件夹中搜索子文件夹.如果找到,请进入此子文件夹并再次搜索子文件夹.如果找到,请进入此子文件夹并搜索子文件夹.如果没有找到,则将此子文件夹中的文件添加到存档中,如果子文件夹为空,则仅添加文件夹名称.然后返回父文件夹并继续搜索下一个子文件夹.如果未找到,则添加此子文件夹的文件.然后回到父文件夹继续搜索子文件夹,依此类推.

如您所见,对整个文件夹树的每个分支反复执行相同的过程,直到处理完所有子文件夹.这是使用递归完成的.每次找到子文件夹时,搜索子文件夹的子程序都会调用自己.

注意:

控制台版本 Rar.exe 仅支持创建/提取 RAR 档案.它不支持 ZIP 档案.这清楚地写在顶部的文本文件Rar.txt 中,这是WinRAR 控制台版本的手册.有必要使用 WinRAR.exe 而不是 RAR.exe 来创建 ZIP 档案.

示例 1:

"%ProgramFiles%WinRARWinRAR.exe" a -afzip -ep1 -ibck -r -y "带路径的 ZIP 文件名称" "%UserProfile%DesktopsomeFolder"

示例 2:

"%ProgramFiles%WinRARWinRAR.exe" a -afzip -ep1 -ibck -r -y "带路径的 ZIP 文件名称" "%UserProfile%DesktopsomeFolder"

GUI 版本 WinRAR.exe 有许多与控制台版本 Rar.exe 相同的命令和开关,但与 -afzip 有不同之处,如下所示code> 仅支持 WinRAR.exe-ibck 而不是 -idq 在后台运行 WinRAR 这意味着最小化到系统托盘而不是前台,带有可见的进度窗口.

有关创建WinRAR.exe 命令行启动WinRAR 的帮助,请单击最后一个主菜单帮助 的第一个菜单项帮助主题,选择帮助选项卡内容,展开列表项命令行模式并使用帮助页面:

  • 命令行语法
  • 按字母顺序排列的命令列表
  • 字母开关列表

在创建WinRAR.exeRar 时,建议从上到下依次阅读帮助页面和文本文件Rar.txt.exe 命令行,用于批处理文件或快捷方式文件 (*.lnk).

Using the WinRAR command line (C:Program FilesWinRAR ar.exe), all I'm trying to do is compress a single folder (C:Users\%username%desktopsomeFolder) and possibly change the name of the .zip file created. I've tried just "rar.exe a "C:Users\%username%desktopsomeFile" and it works, but it compresses another folder (not the one I put).

What am I doing wrong?

Can you also provide explanation (and maybe tell me what recursion is because I'm unfamiliar with it)?

Thanks

解决方案

Use either

"%ProgramFiles%WinRARRar.exe" a -ep1 -idq -r -y "Name of RAR file with path" "%UserProfile%DesktopsomeFolder"

or

"%ProgramFiles%WinRARRar.exe" a -ep1 -idq -r -y "Name of RAR file with path" "%UserProfile%DesktopsomeFolder"

to create a RAR archive file with the specified name after command a (add to archive) and the switches

  • -idq ... enable quiet mode to display only error messages,
  • -ep1 ... exclude base directory from specified file/folder names,
  • -r ... recursively archive/compress all files and subdirectories,
  • -y ... assume Yes on all queries.

The folder someFolder is included in the archive with first command line without a backslash at end.

The folder someFolder is NOT included in the archive, just the files and the subdirectories of this folder, with second command line with the backslash at end.

In other words option -ep1 results in omitting everything from path up to last backslash in specified file or folder name on adding the file or folder to the archive which explains the difference on adding a folder without or with backlash at end specified on command line.

Recursion means to add not only the files in the specified folder, but also all subfolders and all files in all subfolders.

So RAR must search first in the specified folder for a subfolder. If found go into this subfolder and search again for a subfolder. If one is found, go into this subfolder and search for a subfolder. If no one found, add the files in this subfolder into the archive or just the folder name if the subfolder is empty. Then go back to parent folder and continue searching for next subfolder. If none is found, add the files of this subfolder. Then go back to parent folder and continue search for subfolder, and so on.

As you can read, the same procedure is done again and again for each branch of the entire folder tree until all subfolders were processed. This is done using a recursion. The subroutine searching for subfolders calls itself every time a subfolder is found.

NOTE:

Console version Rar.exe supports only creation/extraction of RAR archives. It does not support ZIP archives. This is clearly written in text file Rar.txt at top which is the manual for console version of WinRAR. It would be necessary to use WinRAR.exe instead of RAR.exe to create ZIP archives.

Example 1:

"%ProgramFiles%WinRARWinRAR.exe" a -afzip -ep1 -ibck -r -y "Name of ZIP file with path" "%UserProfile%DesktopsomeFolder"

Example 2:

"%ProgramFiles%WinRARWinRAR.exe" a -afzip -ep1 -ibck -r -y "Name of ZIP file with path" "%UserProfile%DesktopsomeFolder"

GUI version WinRAR.exe has many commands and switches identical to console version Rar.exe, but there are differences as shown here with -afzip supported only by WinRAR.exe and -ibck instead of -idq to run WinRAR in background which means minimized to system tray instead of in foreground with a visible progress window.

For help on creating WinRAR.exe command line start WinRAR, click in last main menu Help on first menu item Help topics, select help tab Contents, expand list item Command line mode and make use of the help pages:

  • Command line syntax
  • Alphabetic commands list
  • Alphabetic switches list

It is advisable to read the help pages in listed order respectively the text file Rar.txt from top to bottom on creating the WinRAR.exe or Rar.exe command line for usage in a batch file or in a shortcut file (*.lnk).

这篇关于只需使用 WinRAR 命令行批量压缩 1 个文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆