2

这是脚本。目标是将文件夹中的 Rar 文件提取到特定文件夹中。问题是我需要 WinRar 的路径才能更改为 Program Files 是 Program Files (x86) 不在系统上。我怎样才能做到这一点?谢谢!

@echo off
@set local

set dirA=C:\Users\%username%\Desktop

\SpearsCraftBox\Batches

set dirE=C:\Users\%username%\AppData

\Roaming\.minecraft

set dirC=C:\Users\%username%\Desktop

\SpearsCraftBox\Batches

cd %dirA%

设置路径="C:\Program Files (x86)\WinRAR\";%path%

echo.
echo All files in %dirA% to be uncompressed
echo.


echo.

FOR %%i IN (*.rar) do (
unrar x "%%~ni.rar" "%dirE%"
move "%%~ni.rar" "%dirC%"
echo completed uncompressing "%%i" and moved 

archives or archive to "%dirC%"
)

goto eof


:eof

echo.
echo "Task Completed"
echo.
4

1 回答 1

3

为 Program Files 目录定义了环境变量:%ProgramFiles%%ProgramFiles(x86)%.

IF EXIST "%ProgramFiles(x86)%\WinRAR" (
  SET pth="%ProgramFiles(x86)%\WinRAR"
)
IF EXIST "%ProgramFiles%\WinRAR" (
  SET pth="%ProgramFiles%\WinRAR"
)


IF NOT EXIST %pth% (
    ECHO WinRar not found.
    GOTO :EOF
)
...
"%pth%unrar" x "%%~ni.rar" "%dirE%"
...
于 2012-09-14T05:55:52.517 回答