if-statement - 如果程序文件(x86)批量不存在,如何将路径=设置为程序文件?

标签 if-statement batch-file path x86 winrar

这是脚本。目标是将文件夹中的 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%

set path="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.

最佳答案

为 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%"
...

关于if-statement - 如果程序文件(x86)批量不存在,如何将路径=设置为程序文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12418242/

相关文章:

用于检查 SetUID 的 Linux 脚本

html - 当变量为负时如何更改背景颜色?

windows - 如何查看 ".bat"文件中的命令行参数?

windows - %date :~-4, 4%%date :~-10, 2%%date :~-7, 2%_%time :~0, 2%%time :~3, 2% 是什么意思?

.net - Path.Combine 如何与两个以上的参数一起使用?

python - 使用列表理解对列表中的奇数求和,for 和 if 在一行中

batch-file - 如何在bash脚本的批处理文件的参数中包含管道字符?

android在不拍照的情况下获取照片路径

c# - WPF : How do I make a editable path

javascript - 使用 JavaScript 允许数字字段中的小数