Re: [BATCH WORLD] Simple deletion script not working correctly under Server 2003
- On 25/08/2011 10:02, Bushy wrote:
>This has a couple of changes but should keep 10 of the latest folders.
> Very quickly, the following is a location where backups are dumped
> nightly, into directory names that are date generated.
> Under each of these directories are around 4 gig of nightly SQL backup
> Each of the dated directory names are created at 10pm on that particular
> date, so they each have a creation date based on their filename.
> At the moment there is around two months worth, and the need to remember
> to manually go in and delete chunks.
> My goal is to automate the process and just to keep the last ten days worth.
> Direction location example:
The syntax should be to remove the folders using RD rather than deleting files.
@echo off & setlocal enableextensions
if not exist "%targetdir_%\" (
echo Folder "%targetdir_%" not found
if exist %script_% del %script_%
for /f "skip=10 delims=" %%f in (
'dir /a:d /b /o:-d "%targetdir_%"') do (
echo rd /s /q "%targetdir_%\%%~nxf">>%script_%
endlocal & goto :EOF
>Posted by: "foxidrive"That worked a treat. Your a legend. Thankyou!
> This has a couple of changes but should keep 10
> of the latest folders. The syntax should be to
> remove the folders using RD rather than deleting files.
(Flippin stupid me trying to do it with DEL. I didn't even put any
thought into that at all; didnt even think about RD /S.)