帮我写个bat程序调用winrar实现如下功能: 1、对当前目录下所有文件夹进行压缩 1、压缩文件夹时自动添加注释,注释从指定txt文档中获取 2、同时添加一个指定文件夹到已经压缩好的压缩包中
时间: 2023-02-22 15:09:24 浏览: 50
这是一个完整的bat脚本,可以实现您描述的功能:
```
@echo off
for /d %%d in (*) do (
set folder=%%d
set comment=
for /f "delims=" %%i in (comment.txt) do set comment=!comment! %%i
"C:\Program Files\WinRAR\WinRAR.exe" a -ep -r -df -m5 -z"comment.txt" "!folder!.rar" "!folder!"
"C:\Program Files\WinRAR\WinRAR.exe" -ep -r -df -m5 -z"comment.txt" "!folder!.rar" "specified_folder"
)
pause
```
请注意:该脚本假定WinRAR安装在C:\Program Files\WinRAR目录下,请根据实际情况修改目录路径。此外,您需要在当前目录下创建一个名为comment.txt的文件,用于存储要添加的注释。
相关问题
帮我写个bat程序实现如下功能: 1、对当前目录下所有文件夹进行压缩 1、压缩文件夹时自动添加注释,注释从指定txt文档中获取 2、同时添加一个指定文件夹到已经压缩好的压缩包中
以下是使用 BAT 批处理脚本实现上述功能的代码示例:
```
@echo off
:: 设置压缩工具的路径
set zip=C:\Program Files\7-Zip\7z.exe
:: 设置注释文件的路径
set comment_file=comment.txt
:: 设置指定文件夹的路径
set target_folder=target
:: 获取当前目录下所有文件夹的列表
for /d %%i in (*) do (
:: 判断当前文件夹是否为指定文件夹,如果是则跳过
if "%%i" == "%target_folder%" (
echo Skipping %target_folder%
continue
)
:: 获取当前文件夹的名称
set folder=%%i
:: 构造压缩文件的名称
set zip_file=%folder%.zip
:: 使用压缩工具对当前文件夹进行压缩,同时添加注释
%zip% a -tzip %zip_file% %folder% -mx9 -mhe -z%comment_file%
:: 将指定文件夹添加到已经压缩好的压缩包中
%zip% u %zip_file% %target_folder%
)
```
上面的代码需要使用 7-Zip 这款压缩工具,请确保它已经正确安装并且可以从命令行使用。可以根据实际情况修改代码中的参数,以适配您的需求。
写个bat程序实现如下功能: 1、压缩文件时自动添加注释,注释从指定txt文档中获取 2、同时添加指定文件夹到压缩文件中
以下是一个使用 Windows 命令行实现上述功能的示例 BAT 文件:
```
@echo off
set commentfile=comment.txt
set folder=sample_folder
set zipfile=sample.zip
if not exist %commentfile% echo The comment file is not found and exit
if not exist %folder% echo The folder is not found and exit
7z a -mx9 -mhe=on -mhc- "%zipfile%" "%folder%" -z%commentfile%
echo The compression is completed.
```
上面的 BAT 文件实现了以下步骤:
1. 设置注释文件(`commentfile`)和要压缩的文件夹(`folder`)的路径,以及压缩文件(`zipfile`)的文件名。
2. 判断注释文件和要压缩的文件夹是否存在,如果不存在则退出。
3. 使用 `7z` 命令对文件夹进行压缩,并使用 `-z` 参数从注释文件中读取注释信息。
4. 显示压缩完成的消息。
请注意,上面的示例使用了 7-Zip 工具,如果您的系统中没有安装 7-Zip,请先安装后再使用。