|
Answer» Hi, I am trying to WRITE a batch file that will find an old file/folder, delete it, and then REPLACE it with a new file/folder? Below is what I have so far, please help:
ECHO OFF
SETLOCAL
SET targetPath=C:\scripts\scripts
SET targetFiles=*.doc
SET aMonthBefore=20090609
FOR /f %%z IN ('dir /b %targetPath%\%targetFiles%') DO (
FOR /f "tokens=1-4 delims=/ " %%a IN ('dir %targetPath%\%%z') DO (
IF "%%c%%a%%b" LSS "9" (
FOR /f "tokens=1-4 delims=(" %%1 IN ("%%c%%a%%b") DO (
IF "%%2"=="" (
IF %%c%%a%%b LSS %aMonthBefore% (
ECHO Detect file older than %aMonthBefore% ::::: -- %%z -- %%c%%a%%b
) ELSE (
ECHO Defect file newer than %aMonthBefore% ::::: -- %%z -- %%c%%a%%b
)
)
)
)
)
) to find and delete an old file, you can use GNU find for windows. (See my sig, search for findutils) eg
Code: [Select]c:\test > find c:\test -type f -NAME "file_to_delete" -delete there are other options also, like find how many days old, etc..
|