I need help on this script...

April 4, 2011 at 17:39:25
Specs: Windows Server 2003
@echo on
for /f "tokens=2-4 delims=/ " %%A in ('echo %DATE%') do (set YY=%%C&SET MM=%%A&SET DD=%%B)

set /a DD=1%DD%-112
set /a MM=1%MM%-100

if %DD% GTR 0 goto end
set /a MM=%MM%-1

if %MM% GTR 0 goto leap

set /a DD=31
set /a MM=12
set /a YY=%YY%-1
REM echo %YY%, %MM%, %DD%
goto end

set /a TT=%YY%/4
set /a TT=%TT%*4
if not %YY% equ %TT% goto mon%MM%
set /a DD=29
goto end

set /a DD=31
goto end

set /a DD=28
goto end

set /a DD=30
goto end

set /a DD=%DD% + 100
set DD=%DD:~1,2%
set /a MM=%MM% + 100
set MM=%MM:~1,2%

echo rmdir /s /q e:\dbbackup\data\%YY%%MM%%DD%

I want to delete backup file which is 12 days ago and this script gives me 20110331.

Please, help me...

See More: I need help on this script...

Report •

April 4, 2011 at 18:13:58
You might want to look at "dateadd.bat" from http://www.robvanderwoude.com/batex...

Report •

April 4, 2011 at 18:18:05
Assuming you can use the modified date - can you use the forfiles command?

forfiles /p e:\dbbackup\data\ -m *.* -d -12 -c "cmd /c del @path"

Report •

April 4, 2011 at 18:34:50
If you can, use a programming language that does the Date maths more easily
Here's a Ruby for Windows script

require 'date'
require 'fileutils'
n=12 #set number of days
Dir["*"].each do |file|
  if (Date.today - File.mtime(file).to_date) >= n
    puts "File more than #{n} days: #{file}"
    puts "Backing up #{file}"
    FileUtils.move(file, "c:\\backup\\dir")

Report •
Related Solutions

Ask Question