Question

Creating batch file for archiving a folder

Dec 6, 2018 10:37PM PST

Hi,
I have created a batch which will copy the contents(sub folders and files) of an existing folder with a specific name (folder name : "BackupFrom")from c:\ drive and create a new folder with a prefix "SampleRetentionBackup" followed by the date time stamp in "yyyy_mm_dd" format like "SampleRetentionBackup_2018_11_28". After, copying i am looking for the same folder SampleRetentionBackup_2018_11_28" which are 1 days old and moving that folder(s) alone to a new folder in d:\Archive where the Archive folder is created on the fly and move the folders which starts with "SampleRetentionBackup". So far it is working fine. But the only issue is instead of moving the folder which are x days old("SampleRetentionBackup_2018_11_28"), it is moving the recent folder ("SampleRetentionBackup_2018_12_07")to the archive folder in d:\drive. I need some help.

Please find the batch file scripting below:
@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%
robocopy %source% /s /e /minage:2 /move d:\Archive\%destination%

Discussion is locked

Follow
Reply to: Creating batch file for archiving a folder
PLEASE NOTE: Do not post advertisements, offensive materials, profanity, or personal attacks. Please remember to be considerate of other members. If you are new to the CNET Forums, please read our CNET Forums FAQ. All submitted content is subject to our Terms of Use.
Reporting: Creating batch file for archiving a folder
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Comments

CNET Forums

Forum Info