I have a question about delimiters in a FOR /F loop. I'm trying to extract the host name and share name from a previously specified network path (\\server\share).
I can extract the server/host name using the following command:
Code: Select all
SET NTWK=\\computer1\folder1$
FOR /F "TOKENS=1 DELIMS=\" %%a IN ('ECHO %NTWK%') DO SET HOST=%%a
I can also extract the share name using the following command:
Code: Select all
SET NTWK=\\computer1\folder1$
FOR /F "TOKENS=2 DELIMS=\" %%a IN ('ECHO %NTWK%') DO SET SHARE=%%a
Now here is where the issue comes in: If the share name specified is, lets say, folder1$\folder2, then the FOR /F loop will only give me folder1 as the result. For example:
Code: Select all
SET NTWK=\\computer1\folder1$\folder2
FOR /F "TOKENS=2,3 DELIMS=\" %%a IN ('ECHO %NTWK%') DO SET HOST=%%a
ECHO %SHARE%
folder1$
Thanks in advance!