如何使用批处理文件将多个文件夹压缩为一个rar存档文件? [英] How to compress multiple folders into one rar archive file with batch file?

查看:447
本文介绍了如何使用批处理文件将多个文件夹压缩为一个rar存档文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使我的批处理文件将多个文件夹压缩为一个压缩文件,但没有成功.它仅适用于set src="D:\test1"这样的一个文件夹.有人可以帮忙吗?

这是我的批次:

@echo off
echo STARTING BACKUP...
echo %date% %time%
echo+

:: variables
set src="D:\test1" + "D:\test2" + "D:\test3"
set dest=D:\Backups

set filename=%DATE:/=-%_%TIME::=-%
set filename=%filename: =%
Set Rar=%ProgramFiles%\WinRar\WinRAR.exe

"%Rar%" a -m5 -ed -pEltyar -r %dest%\%filename%.rar "%src%"

echo Backup Completed!
@pause

解决方案

阅读使用应用程序的手册非常有用.控制台版本Rar.exe的手册是 WinRAR 的程序文件文件夹中的文本文件Rar.txt.可以通过鼠标左键双击该文件来打开它.可以从上至下阅读文本手册,以构建特定压缩或提取任务所需的命令行.

GUI版本WinRAR.exe的手册是帮助文件WinRAR.chm,也可以通过双击该文件或在已经运行的 WinRAR 中单击最后一个菜单,来打开该文件. >第一个菜单项帮助主题中的帮助.第一个帮助选项卡内容包含列表项目命令行模式,其中列表结构化且已经正确排序,这些帮助页面对于构建特定任务的命令行很有用. >

您编写的整个批处理文件可以用单个命令行替换:

使用控制台版本Rar.exe:

@"%ProgramFiles%\WinRAR\Rar.exe" a -agYYYY-MM-DD_HH-MM -cfg- -ed -ep1 -inul -m5 -pEltyar -r -y -- D:\Backups\ "D:\test1" "D:\test2" "D:\test3"

例如,如果要在运行此命令行时查看Rar.exe在做什么,请用-idcp-idcdp替换开关-inul.

使用GUI版本WinRAR.exe:

@"%ProgramFiles%\WinRAR\WinRAR.exe" a -agYYYY-MM-DD_HH-MM -cfg- -ed -ep1 -ibck -m5 -pEltyar -r -y -- D:\Backups\ "D:\test1" "D:\test2" "D:\test3"

我建议使用D:\Backups\Backup_.rar而不只是D:\Backups\来创建文件名为Backup_YYYY-MM-DD_HH-MM.rar而不是YYYY-MM-DD_HH-MM.rar的RAR档案,但这是您的选择.

I try to get my batch file to compress more than one folder into one compressed file but with no success. It only works with one folder like that set src="D:\test1". Can anyone help please?

Here is my batch:

@echo off
echo STARTING BACKUP...
echo %date% %time%
echo+

:: variables
set src="D:\test1" + "D:\test2" + "D:\test3"
set dest=D:\Backups

set filename=%DATE:/=-%_%TIME::=-%
set filename=%filename: =%
Set Rar=%ProgramFiles%\WinRar\WinRAR.exe

"%Rar%" a -m5 -ed -pEltyar -r %dest%\%filename%.rar "%src%"

echo Backup Completed!
@pause

解决方案

It is very often useful to read the manual on using an application. The manual for console version Rar.exe is the text file Rar.txt in program files folder of WinRAR. It can be opened by double clicking on this file with primary (left) mouse button. The text manual can be read from top to bottom to build the command line required for a specific compression or extraction task.

The manual for GUI version WinRAR.exe is the help file WinRAR.chm which can be also opened by double clicking on this file or from within an already running WinRAR by clicking in last menu Help on first menu item Help topics. The first help tab Contents contains the list item Command line mode with listing structured and already right ordered the help pages being useful to build the command line for a specific task.

The entire batch file written by you can be replaced by a single command line:

With using the console version Rar.exe:

@"%ProgramFiles%\WinRAR\Rar.exe" a -agYYYY-MM-DD_HH-MM -cfg- -ed -ep1 -inul -m5 -pEltyar -r -y -- D:\Backups\ "D:\test1" "D:\test2" "D:\test3"

Replace switch -inul for example by -idcp or -idcdp if you want to see what Rar.exe is doing while running this command line.

With using the GUI version WinRAR.exe:

@"%ProgramFiles%\WinRAR\WinRAR.exe" a -agYYYY-MM-DD_HH-MM -cfg- -ed -ep1 -ibck -m5 -pEltyar -r -y -- D:\Backups\ "D:\test1" "D:\test2" "D:\test3"

I would suggest to use D:\Backups\Backup_.rar instead of just D:\Backups\ to create the RAR archives with file name Backup_YYYY-MM-DD_HH-MM.rar instead of just YYYY-MM-DD_HH-MM.rar, but that's your choice.

这篇关于如何使用批处理文件将多个文件夹压缩为一个rar存档文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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