如何在 Winrar window 资源管理器中编辑 .bat 文件?

How to edit a .bat file in the Winrar window explorer?

Winrar有没有另一种直接在资源管理器中编辑bat文件的方法?

我点击一个 zip 文件,它会显示一个包含许多文件的 Winrar 弹出窗口,双击某个文件在默认程序中打开它(Notepad++ 中的 .txt,Toad 中的 .sql,等等),但在 bat 文件中双击 运行 蝙蝠。 Alt + v 是查看文件的快捷方式,但它不允许我编辑bat文件。

唯一的方法是将文件拖到 Windows,编辑并拖回 Windows。

WinRAR 具有将双击文件临时解压缩到 临时文件文件夹 的功能,如选项卡 中所定义设置中的路径从菜单选项打开,然后启动与该文件关联的应用程序,并在启动的应用程序终止后,重新打包文件(如果有任何修改)回到存档中。

这也适用于可执行文件,除了 安全性 选项卡上的 从提取中排除的文件类型 选项在 [=68] 中启用=]Settings 从菜单 Options 打开,默认情况下提取整个存档,如 Unpack everything for 选项卡 [=68] =]查看器 设置

但是可以在 设置查看器 选项卡上自定义双击的默认行为。在为 Viewer type 选择 Ask 而不是 Internal viewer 并输入 C:\Windows\Notepad.exe 作为 外部查看器名称 双击存档内的 *.bat 文件会提示用户使用内部或外部查看器查看或使用相关程序打开文件。当然 *.bat 不应该在设置列表 Unpack everything for.

现在点击按钮外部查看器(Notepad.exe),批处理文件被提取到临时文件文件夹,然后 Notepad 使用该文件启动以供查看和编辑。当完成 viewing/editing 批处理文件并退出 Notepad 时,WinRAR 检测到修改并询问用户是否应更新修改后的文件存档。

每个 设置 对话框中都有 帮助 按钮。请利用它并阅读 WinRAR.

的帮助

如果始终要编辑存档文件中的同一个批处理文件,我建议使用批处理文件尽可能地自动执行此任务。

@echo off
setlocal
set "FileToEdit=Test.bat"
set "PathInArchive="
set "DefaultArchive=C:\Temp\Test.zip"

rem Set a title for the command prompt window and determine name
rem of this batch file with full path for a possible error message.
title Update %FileToEdit%
set "BatchFile=%~f0"

rem Use a standard archive file if none is specified as first parameter.
if "%~1"=="" (
    set "ArchiveFile=%DefaultArchive%"
) else (
    set "ArchiveFile=%~f1"
)

rem Test if the archive file exists at all.
if not exist "%ArchiveFile%" (
    call :ErrorMessage "Archive file %ArchiveFile% does not exist."
    exit /B
)

rem Make sure path in archive ends with a backslash
rem if a path to file in archive is defined at all.
if not "%PathInArchive%" == "" (
    if not "%PathInArchive:~-1%" == "\" (
        set "PathInArchive=%PathInArchive%\"
    )
)

rem Extract the file to edit to directory for temporary files.
"%ProgramFiles%\WinRAR\WinRAR.exe" e -cfg- -ibck -y -- "%ArchiveFile%" "%PathInArchive%%FileToEdit%" "%TEMP%\"
if errorlevel 1 (
    call :ErrorMessage "Failed to extract file %PathInArchive%%FileToEdit%"
    exit /B
)

rem Start Windows Notepad to edit the temporary extracted file.
start "" /wait %windir%\Notepad.exe "%TEMP%\%FileToEdit%"

rem Define the option -ap with path in archive if needed at all.
set "ArchivePath="
if not "%PathInArchive%" == "" set "ArchivePath=-ap"%PathInArchive%""

rem Update the edited file in archive and delete it on success.
"%ProgramFiles%\WinRAR\WinRAR.exe" u %ArchivePath% -cfg- -df -ibck -ep -y -- "%ArchiveFile%" "%TEMP%\%FileToEdit%"
if errorlevel 1 (
    del "%TEMP%\%FileToEdit%" 2>nul
    call :ErrorMessage "Failed to update file %PathInArchive%%FileToEdit%"
    exit /B
)

rem Exit batch processing.
exit /B

rem Subroutine to output an error message.
:ErrorMessage
echo Error detected by:  %BatchFile%
echo On processing file: %ArchiveFile%
echo.
echo Error: %~1
echo.
endlocal
pause
exit /B

分配给批处理文件顶部的变量 FileToEditPathInArchiveDefaultArchive 的值应适当定义。

通过在文件夹 %USERPROFILE%SendTo 子文件夹中创建此批处理文件的快捷方式 (*.lnk),并使用合适的名称,右键单击存档文件要在存档内使用固定名称和路径修改的批处理文件,然后单击此快捷方式上的子菜单 发送到 ,结果将批处理文件提取到临时文件文件夹,打开 Windows Notepad 用于编辑和重新打包后最终将修改后的批处理文件放入存档文件中。

WinRAR 中打开菜单 帮助 中的 帮助主题 并单击选项卡 内容 项目命令行模式。此内容列表项下的帮助页面解释了使用的 Commands eu 以及使用的 Switches

要了解使用的命令及其工作原理,请打开命令提示符 window,在其中执行以下命令,并仔细阅读为每个命令显示的所有帮助页面。

  • call /?
  • del /?
  • echo /?
  • endlocal /?
  • exit /?
  • if /?
  • pause /?
  • rem /?
  • set /?
  • setlocal /?
  • start /?
  • title /?
  1. 从 WinRAR,单击 选项 -> 设置 -> 查看器.

  2. Ask" 激活为 查看器类型

  3. 外部查看器名称.

  4. 中粘贴%WINDIR%\notepad.exe或您最喜欢的编辑器的路径
  5. 单击确定。完成。

现在,当您双击存档中的任何非 exe 文件时,会弹出一个窗口让您选择如何打开它:

  • 内部

  • 外部(通过记事本或您的编辑器)

  • 关联程序