Question

The goal of my overall script is to - from a central server - check individual site servers for files. If files exist, go do some work. This smaller exerpt is to aid creation of multiple entries for site names, logs, dates, and times of which I want to check the UNC path and use a variable for the site server name - the first 'token' of the UNC path. I used the example guide from Rob van der Woude's scripting page (these loops are new to me and it appears to be a basic resource) to create the FOR loop exampled below.

@echo off
SET PATH=\\UNCMainPath\SubPath1\SubPath2
FOR /F "tokens=1 delims=\" %%A IN (%PATH%) DO SET FOLDER=%%A
ECHO %FOLDER%

This is short and clean and will be easy to repeat for ~50 site servers. This code, however, does not work. The error I receive is:

The system cannot find the file \\UNCMainPath\SubPath1\SubPath2.

ECHO is off.

This, of course, tells me something is wrong before the FOR loop begins, but for the life of me I can't figure what is incorrect. Even with trash example text, I've been able to SET a variable and have it ECHO back as whatever it was set for. What have I done wrong?

Was it helpful?

Solution

Thank you to @Endoro.

Using ("%PATH%") did the trick. I forgot to enclose the variable with quotes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top