archiving a folder and its contents to another drive which are 1 day old RRS feed

  • Question

  • Hi,

    I have created a batch file which will take a backup from a folder called BackupFrom and its contents in c:\ drive and create a new folder in c:\ drive with the name "SampleRetentionBackup_2018_11_28". It is working fine. 

    My requirement is i want to move the folder "SampleRetentionBackup_2018_11_28" and its subfolders and files in to a new drive d:\Archive which is one day old and delete it from c:\drive.

    I searched in google but i am unable to find the right command. My code is moving the folder alone and not its contents.

    Any help is greatly appreciated.

    Here is my code:

    @echo off
    cd c:\ 
    set source=SampleRetentionBackup_%date:~10,4%_%date:~4,2%_%date:~7,2%
    mkdir %source%
    robocopy C:\BackupFrom %source% *.* /S
    set destination=SampleRetentionBackup_%date:~10,4%_%date:~4,2%_%date:~7,2%
    mkdir %destination%
    if not exist d:\Archive\%destination% mkdir d:\Archive\%destination%
    cd d:\Archive\%destination%
    forfiles %source% /s /d -1 /c "cmd /c move %destination%"

    Thursday, November 29, 2018 9:44 AM