Вопрос

I have tested this so far from a test directory without error but I will need the script to call directories on other servers. As soon as I try to add the UNC for the directory where the batch file is located the script fails to create %SITE%.txt.

This is the problematic line:

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

Full file:

@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

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

Другие советы

It needs to be on one line or use parentheses.

for /f "delims=" %%a in ('dir /b /a-d *.DONE ^| find "%SITE%" /c') do set/p "=%%a,">>%SITE%.txt <nul
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top