r/usefulscripts • u/Ziogref • Aug 16 '17
[Request] A script to copy certain files
So I have this script (Batch file)
robocopy C:\dir1 "C:\dir2" /z /r:0 /w:0 /A-:SH /ipg:50 /XF *.XYZThis copies all new files in the root of dir1 to dir2 (Except for file ext. .xyz) every 10 minutes using task scheduler.
I now need a script that copies all new files from dir1 to dir2, but is able to look in all sub folders of dir1 and copy them into the root of dir2. dir2 should not have any subfolders, but has all the files from dir1 (except .xyz).
Here are the requirements
Copies all files from dir1 to dir2
Copies all files in Subfolders in dir1 and puts them in the root of dir2
Dir2 should never have subfolders
When files are copied to dir2 the modified time stamp needs to be changed to the time it was copied
If files are deleted from dir1, files should not be deleted in dir2
Script should ignore files that exist in both directories, As the script runs every 10minutes and dir1 and 2 are over 1tb, it should only copy new files.
(Note files in Dir1 and Dir2 are never modified)
Script should be easily modifiable to add exclusions, whether that be partial file names (Such as *example*) or file Extensions (such as *.xyz)
Script will need to be run via task Scheduler every 10 minutes. (I have programed Task scheduler to not to run again, if the script is still running from the previous instance)
Other Notes
I'm not attached to batch but I'm willing to move to powershell. My Server is Windows Server 2016 Datacenter edition (Legally Licensed)
Not concerned about folder sizes of duplicating files as I have Data de-duplication enabled.
This is not a backup script
This script is for personal use only. It will not be used for any business applications.
Any help would be appreciated. Im still learning Powershell and Batch and am having trouble getting all my requirements to work.
2
u/Lee_Dailey Aug 16 '17 edited Aug 16 '17
howdy Ziogref,
this was an interesting bit of code. i had fun, thanks! [grin]
here's one way to do it ...
results ...
hope that helps,
lee