Version 2.0

Tags | |

Using a batch file to calculate dates

Subtracting 1 year from today example:

    @echo off
    echo Todays date is %date:~4,2%-%date:~7,2%-%date:~10,4%
    echo one year back...
    set /a yearback=%date:~10,4%-1
    Echo is  %date:~4,2%-%date:~7,2%-%yearback%
    pause

Here is what you can do with this. Say you have a "Junk" folder and you only want keep items for 1 year. Using the above method you can subtract a year in the batch file and then using the xcopy and delete commands copy all old files to a temp folder and delete them all. I have provided an example below of this.

    @echo off
    Echo #####################
    Echo This tool will move old files to a temp folder for review
    Echo #####################
    set /a yearback=%date:~10,4%-1
    Xcopy C:\old_folder\* /s /d:%yearback%-%date:~7,2%-%date:~10,4% C:\review_folder\
    pause
    exit


Comments

Feel free to leave a comment or question

Name: (Optional but appreciated):

Comment:

Use [code] [/code] for code block style


Newest content

Installing Redmine on CentOS 6.5
2014-06-25 00:00:00
centos,linux


Mavericks install "This copy of the Install OS X Mavericks application can't be verified"
2014-03-14 11:49:58
mavericks,osx


Openindiana Public key SSH issue
2014-01-08 21:46:56
opensolaris,openindiana


News

Programming:

Security / OS

Technology:

Positive SSL on a transparent background