It's a wonderful life !

日常のつぶやきや、病気のことを語ります

1週間以上前のファイルを削除するバッチファイル

サーバ上のフォルダに格納されているファイルのうち、タイムスタンプが1週間以上前のものを削除するバッチファイル。

 
folder_name2配下のファイルが対象となる。(サブフォルダを含む)
フォルダは削除しない。
 

 

pushd \\192.168.0.1\folder_name1\folder_name2
if %ERRORLEVEL% EQU 0 (
    forfiles /P . /S /D -7 /C "cmd /c if /i @isdir equ true (echo @file is dir.) else (echo del @file)"
    forfiles /P . /S /D -7 /C "cmd /c if /i @isdir neq true (del @file)"
    popd
) else (
    echo フォルダが存在しません。
)