Dos Batch File script to run datewise backup

Hello Experts,

I have a security camera server in which recordings are saved every hourly and daywise.

My requirement is to keep the data of 1 week in the server and rest of the saved files i want to transfer it to external HDD. I need a script which will check the date of the files created and if the date is greater then 7 days, it will copy those files to backup and delete from the server disc.
Hiren LapsiwalaManager - Information TechnologyAsked:
Who is Participating?
oBdAConnect With a Mentor Commented:
One addition to robocopy in http:#a39561459: the current command line will only copy files directly in the source folder ("C:\Recordings"); if the files are organized in a subfolder structure, you need to add /s to the options to process subdirectories as well.
No need for a script: just use robocopy (part of the OS since Vista/W2k8, part of the Resource Kit for XP/W2k3,
robocopy.exe "C:\Recordings" "R:\Backup\Recordings" *.* /minage:7 /mov

Open in new window

The first argument is the source folder(!), the second argument the target folder(!), then the file(s) and/or file masks to copy. /minage:7 copies only files that are older than 7 days, and /mov moves (deletes after the copy) the source files copied, but not the folders.
Enter "robocopy /?" for a list of other options that might be useful for you.
Try this :

set folder="c:\folder"
set days=7
forfiles -p %folder% -s -m *.* -d -%days% -c "cmd /c del @FILE"
Hiren LapsiwalaManager - Information TechnologyAuthor Commented:
Thanks and it is working fine..
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.