I am attempting to search the windows path variable to see if a directory exists in it. And If it does not, add it.
My code is as follows:
@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
)
)
The issue I am getting must occur in the else statement. When I replace the SET PATH with echo NOT FOUND
everything works perfectly. However, when I use the line to set the path variable, it returns "\Common was unexpected at this time"; while %cd% should not include "common" as I am running from the desktop
I had run it once before and it ran perfectly and everything functioned, I went to reboot and now the same code does not achieve the same result.
After some debugging, I found that the issue is actually in the line echo %VAR1% > text.txt
Turning echo on displays the following:
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.
Am I doing something wrong?