如何使用UNC运行for语句?

时间:2013-07-18 22:39:53

标签: for-loop batch-file unc

到目前为止,我已经从测试目录中测试了这个没有错误,但我需要脚本来调用其他服务器上的目录。一旦我尝试将UNC添加到批处理文件所在的目录,脚本就无法创建%SITE%.txt。

这是有问题的一行:

for /f "delims=" %%a in ('dir /b /a-d *.DONE ^| find "%SITE%" /c') do <nul

完整档案:

@ECHO OFF
SET LIMIT=7
SET SITE=04338
SET SITEFOLDER=D:\Test\Veracity
SET SITEFILE="%SITE%.txt"
SET SAVEFILE="count%SITE%.txt"
SETLOCAL ENABLEDELAYEDEXPANSION

REM Get the current count or start a new file if it does not exist.
IF EXIST %SAVEFILE% GOTO READFILE
ECHO 0 >%SAVEFILE%
:READFILE
SET /P COUNT= <%SAVEFILE%

REM Increment the save file value by one.
FOR %%B IN ( "%SAVEFILE%" ) DO (
  CALL :ADD_ONE
)
ECHO %COUNT% >%SAVEFILE%

for /f "delims=" %%a in ('dir /b /a-d *.DONE ^| find "%SITE%" /c') do <nul

set/p "=%%a,">>%SITE%.txt

GOTO CHECK_VALUE
:ADD_ONE
SET /A COUNT+=1
GOTO :EOF

REM Conditionally reset the counter and do something.
:CHECK_VALUE
IF %COUNT% LSS %LIMIT% EXIT /B
DEL %SAVEFILE% 2>NUL
IF EXIST %SITEFILE% DEL %SITEFILE%

ECHO

2 个答案:

答案 0 :(得分:1)

需要在一行或使用括号。

for /f "delims=" %%a in ('dir /b /a-d *.DONE ^| find "%SITE%" /c') do set/p "=%%a,">>%SITE%.txt <nul

答案 1 :(得分:0)

for /f "delims=" %%a in (' dir "[UNC PATH]\*.DONE" /b /a-d ^| find "%SITE%" /c') do (set /p "=%%a,">>%SITE%.txt <nul)