0

FORFILESWindows Server 2012R2サーバーのコマンドプロンプトウィンドウでコマンドを利用しようとする非常に単純なバッチスクリプトがあります...

このバッチ ファイルの目的は、一連のディレクトリ (サブ ディレクトリを含む) を調べて、X 日以上前のファイルを削除することです。

@ECHO OFF
CLS
SETLOCAL EnableDelayedExpansion EnableExtensions

SET "MINDAYSOLD=9"
SET "TARGETPATH=E:\archives"

SET "PADDEDTIME=%TIME: =0%"
SET "DATESTAMP=%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%"
SET "LOGFILEPATH=Logs\%~n0-%DATESTAMP%.log"
SET "WORKINGDIR=%~dp0"

CALL :CreateDirectory "%WORKINGDIR%Logs"

ECHO Wiping files that are %MINDAYSOLD% or more days old...
ECHO Target Path: "%TARGETPATH%"
ECHO.

ECHO Searching folder: %TARGETPATH%
FOR /F "usebackq delims=" %%b IN (
        `forfiles /p "%TARGETPATH%" /S /M *.* /D -%MINDAYSOLD% /C "cmd /C ECHO @path" 2^>nul`
) DO (
        SET "filepath=%%~b"
        SET "filename=%%~nxb"
        ECHO   Found !filepath!
        ECHO   Deleting !filename!
        DEL /F /Q /A "!filepath!"
        REM TIMEOUT /NOBREAK /T 1
        IF EXIST "!filepath!" (
                ECHO   Error deleting file^^!
        ) ELSE (
                ECHO   Success.
        )
)
ECHO   Checking if folder %TARGETPATH% is empty...
SET "filesearch="
FOR /F "usebackq delims=" %%c IN (
        `DIR /B /A-D "%%~a" 2^>nul`
) DO (
        SET "filesearch=%%c"
)
IF {!filesearch!}=={} (
        ECHO   Folder is empty, deleting folder...
        RD /Q "%TARGETPATH%"
        REM TIMEOUT /NOBREAK /T 1
        IF EXIST "%TARGETPATH%" (
                ECHO   Error deleting folder^^!
        ) ELSE (
                ECHO   Success.
        )
) ELSE (
        ECHO   Folder is NOT empty^^!  Skipping deleting.
)
ECHO.

EXIT /B %ERRORLEVEL%


REM =================================================================
REM ! FUNCTIONS                                                     !
REM =================================================================

REM == Create directory =============================================
:CreateDirectory
IF NOT EXIST "%~1" (
        MKDIR "%~1"
)
EXIT /B 0
REM =================================================================

フォルダーには多くのファイルがあり、1 日前のファイルを取得しようとしています。何らかの理由で、コマンドは次を返し続けます...

...
ERROR: The parameter is incorrect.
ERROR: The parameter is incorrect.
ERROR: The parameter is incorrect.
ERROR: The parameter is incorrect.
ERROR: The parameter is incorrect.
ERROR: The parameter is incorrect.
ERROR: The parameter is incorrect.
ERROR: The parameter is incorrect.

test
test
...

なぜ世界でこれらのエラーが発生するのかを理解しようとしています。何か案は?

4

1 に答える 1