Brendan Ford
asked on
Move files older than “x” days, and overwrite if already in destination folder
Hello
I mange a bunch of daily generated files for our company, which has many properties, and I am having trouble with my script. Here is our workflow; each property copies their files to a company folder in their property sub-folder. Then every week I run a script to move all files that are older than 10days to a subfolder for the year.
Folder structure = \\server\company\property\ year\
Here is my problem, if I use robocopy, and if the a copy of the file in the “property” and the “year” it doesn’t move it and the property folder is not cleaned up.
If I use xcopy I can use the “/Y” switch and the file in the “year” folder will be overwritten, but I can’t find a switch in xcopy that only moves files that “x” days old.
Here is what I have tried:
Using robocopy I tried /is (/IS = Include Same, overwrite files even if they are already the same.) switch and that doesn’t work.
Using xcopy I tried /d:08/19/2016 (/d:date = Copies files changed on or after the specified date) and that doesn’t work because I am looking for before that date note after.
So in short I am looking for either a “xcopy” or “robocopy” script that’s moves files that are 10days old or older from “property” to “year”, and if there is a copy of the file already in the “year” folder overwrite it.
Any help would be great.
I mange a bunch of daily generated files for our company, which has many properties, and I am having trouble with my script. Here is our workflow; each property copies their files to a company folder in their property sub-folder. Then every week I run a script to move all files that are older than 10days to a subfolder for the year.
Folder structure = \\server\company\property\
Here is my problem, if I use robocopy, and if the a copy of the file in the “property” and the “year” it doesn’t move it and the property folder is not cleaned up.
If I use xcopy I can use the “/Y” switch and the file in the “year” folder will be overwritten, but I can’t find a switch in xcopy that only moves files that “x” days old.
Here is what I have tried:
Using robocopy I tried /is (/IS = Include Same, overwrite files even if they are already the same.) switch and that doesn’t work.
Using xcopy I tried /d:08/19/2016 (/d:date = Copies files changed on or after the specified date) and that doesn’t work because I am looking for before that date note after.
So in short I am looking for either a “xcopy” or “robocopy” script that’s moves files that are 10days old or older from “property” to “year”, and if there is a copy of the file already in the “year” folder overwrite it.
Any help would be great.
robocopy should work -- what is the exact syntax you are using; something like this?
robocopy \\server\company\property \\server\MOVED\company\pro perty\year /minage:11 /s /MOVE see this link for added details http://social.technet.microsoft.com/wiki/contents/articles/1073.robocopy-and-a-few-examples.aspx#Move_files_over_14_days_old
robocopy \\server\company\property \\server\MOVED\company\pro
ASKER
Thanks "NVIT" I am not familiar with "FORFILES" script and or syntax.
The issue is not setting the date in robocopy but forcing it to overwrite the files that are already in the destination folder.
The issue is not setting the date in robocopy but forcing it to overwrite the files that are already in the destination folder.
ASKER
Hi "lionelmm" thanks for the response.
Here are the two syntax I have been using: I must admit I stole the first line that gives me today's date I don't know how it work or to force that to calculate 10day ago instead of today
So that is why I have been using robocopy for this script
FOR /F "tokens=2 delims= " %%V IN ("%DATE%") DO SET TDY=%%V
xcopy \\server\company\property\ *.txt \\server\company\property\ year\ /d:%TDY% /q /y /c
************************** ********** ********** ********** ********** ********** *
robocopy "\\server\company\property " "\\server\company\property \year" /MOV /IF *.txt /MINAGE:10
Here are the two syntax I have been using: I must admit I stole the first line that gives me today's date I don't know how it work or to force that to calculate 10day ago instead of today
So that is why I have been using robocopy for this script
FOR /F "tokens=2 delims= " %%V IN ("%DATE%") DO SET TDY=%%V
xcopy \\server\company\property\
**************************
robocopy "\\server\company\property
> If I use xcopy I can use the “/Y” switch and the file in the “year” folder will be overwritten, but I can’t find a switch in xcopy that only moves files that “x” days old
That what FORFILES is for: to find the files 10 days and older. Then pass them to XCOPY
Type FORFILES /? to see the different options/switches.
That what FORFILES is for: to find the files 10 days and older. Then pass them to XCOPY
Type FORFILES /? to see the different options/switches.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
If you want to filter based on 10 days older than current date:
Open in new window
robocopy also has date filtering switch /MINAGE:20160819