我正在尝试搜索 Windows 路径变量以查看其中是否存在目录。如果没有,请添加它。
我的代码如下:
@echo off
SET VAR1=%path%
echo %VAR1% > text.txt
FOR /f "tokens=* delims=;" %%a IN (text.txt) DO (
echo.%%a|findstr /C:"app0" >nul 2>&1
if not errorlevel 1 (
echo Directory was Found
) else (
SET PATH=%PATH%;%cd%\app0
)
)
我遇到的问题必须出现在 else 语句中。当我将 SET PATH 替换为echo NOT FOUND
一切正常时。但是,当我使用该行设置路径变量时,它返回“\Common was unexpected at this time”;而 %cd% 不应该包括“common”,因为我是从桌面运行的
我之前运行过一次,它运行完美,一切正常,我重新启动,现在相同的代码没有达到相同的结果。
经过一番调试,我发现问题实际上是在行echo %VAR1% > text.txt
打开回显会显示以下内容:
echo C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R)
> Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R)
> Management Engine
> Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program
> Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program
> Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files
> (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program
> Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program
> Files\Intel\WiFi\bin\;C:\Program Files\Common
> Files\Intel\WirelessCommon\;C:\Program Files (x86)\Common
> Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R)
> Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R)
> Management Engine
> Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program
> Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program
> Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files
> (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program
> Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program
> Files\Intel\WiFi\bin\;C:\Program Files\Common
> Files\Intel\WirelessCommon\;C:\Users\Bryan
> Douglas\AppData\Local\Microsoft\WindowsApps;C:\Program
> Files\Intel\WiFi\bin\;C:\Program Files\Common
> Files\Intel\WirelessCommon\; 1>text.txt
> \Common was unexpected at this time.
难道我做错了什么?