07-23-2023, 08:12 AM
Just as an alternative:
1. In the folder you are going to search the `PATH` variable for, create a temporary file with such an unusual name that you would never ever expect any other file on your computer to have.
2. Use the standard batch scripting construct that lets you perform the search for a file by looking up a directory list defined by some environment variable (typically `PATH`).
3. Check if the result of the search matches the path in question, and display the outcome.
4. Delete the temporary file.
This might look like this:
@ECHO OFF
SET "mypath=D:\the\searched-for\path"
SET unusualname=nowthisissupposedtobesomeveryunusualfilename
ECHO.>"%mypath%\%unusualname%"
FOR %%f IN (%unusualname%) DO SET "foundpath=%%~dp$PATH:f"
ERASE "%mypath%\%unusualname%"
IF "%mypath%" == "%foundpath%" (
ECHO The dir exists in PATH
) ELSE (
ECHO The dir DOES NOT exist in PATH
)
Known issues:
1. The method can work only if the directory exists (which isn't always the case).
2. Creating / deleting files in a directory affects its 'modified date/time' attribute (which may be an undesirable effect sometimes).
3. Making up a globally unique file name in one's mind cannot be considered very reliable. Generating such a name is itself not a trivial task.
1. In the folder you are going to search the `PATH` variable for, create a temporary file with such an unusual name that you would never ever expect any other file on your computer to have.
2. Use the standard batch scripting construct that lets you perform the search for a file by looking up a directory list defined by some environment variable (typically `PATH`).
3. Check if the result of the search matches the path in question, and display the outcome.
4. Delete the temporary file.
This might look like this:
@ECHO OFF
SET "mypath=D:\the\searched-for\path"
SET unusualname=nowthisissupposedtobesomeveryunusualfilename
ECHO.>"%mypath%\%unusualname%"
FOR %%f IN (%unusualname%) DO SET "foundpath=%%~dp$PATH:f"
ERASE "%mypath%\%unusualname%"
IF "%mypath%" == "%foundpath%" (
ECHO The dir exists in PATH
) ELSE (
ECHO The dir DOES NOT exist in PATH
)
Known issues:
1. The method can work only if the directory exists (which isn't always the case).
2. Creating / deleting files in a directory affects its 'modified date/time' attribute (which may be an undesirable effect sometimes).
3. Making up a globally unique file name in one's mind cannot be considered very reliable. Generating such a name is itself not a trivial task.