Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I create a Robocopy script that will copy new files from folder A to folder B then delete files on folder A that are older than 365 days.

Posted on 2014-08-25
6
Medium Priority
?
263 Views
Last Modified: 2014-09-03
How do I create a Robocopy script that will copy new files from folder A to folder B then delete files on folder A that are older than 365 days.

Here is my current script to copy
C:\WINDOWS\system32\ROBOCOPY.EXE "D:\Folder A" "S:\Folder B" *.* /NP /B /Z /E /R:10 /W:30 /M /copyall /V /COPY:DT /LOG:Audioback.txt

I would also like the script to let me know which files were deleted in folder A.

Bonus would be to have script also zip the deleted files.
0
Comment
Question by:Robert Thun
  • 3
  • 3
6 Comments
 
LVL 6

Assisted Solution

by:Bxoz
Bxoz earned 1500 total points
ID: 40283608
Hello,

You can use  forfiles

forfiles /p D:\Folder A /s /m *.* /d -365 /c "cmd /c del @file"
0
 
LVL 1

Author Comment

by:Robert Thun
ID: 40283655
Will that send me a list of the deleted files?
0
 
LVL 6

Assisted Solution

by:Bxoz
Bxoz earned 1500 total points
ID: 40283714
No but

forfiles /p D:\Folder A /s /m *.* /d -365 /c "cmd /c del @file && echo @path >> C:\Path\To\Log.txt"

Will log all deleted files
0
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
LVL 1

Author Comment

by:Robert Thun
ID: 40283739
Thanks I will test this.
0
 
LVL 1

Author Comment

by:Robert Thun
ID: 40287883
I tested this and it is not deleting the hidden files in the structure. Any way to curtail this issue?
Was thinking this?
forfiles /p D:\Folder A /s /m *.* /d -365 /c "cmd /c del /a:HR @file && echo @path >> C:\Path\To\Log.txt"

Also is there a way to verify that the file is in Folder B before removing it from Folder A?

Is this script looking at modified or created date?
0
 
LVL 6

Accepted Solution

by:
Bxoz earned 1500 total points
ID: 40288852
Ok, This is the code to check if the file exist in folderB before removing file in folderA

forfiles /p FolderA /s /m *.* /d -365 /c "cmd /c IF EXIST FolderB\@file (del @file && echo @path >> Log.txt) ELSE ( echo @file missing >> Log.txt)"


If you need to delete hidden files you can add another line

forfiles /p FolderA /s /m *.* /d -10 /c "cmd /c IF EXIST FolderB\@file (del /AH @file && echo @path >> Log.txt) ELSE ( echo @file missing >> Log.txt)"


The script will check the last modified date you can check forfiles /?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question