Solved

Copy every new file to a folder automatically

Posted on 2010-09-04
20
589 Views
Last Modified: 2012-05-10
Hi Guys,

How can I "cut" all new files from folder A and paste them to folder b  and c automatically?

Maybe every 1 min or so?
Thanks
0
Comment
Question by:masdf123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 3
  • +2
20 Comments
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 400 total points
ID: 33605003
If you want to make exact mirrors, robocopy can be used. Called without any switches, only with source and destination path, it only copies changed or new files:

robocopy SourceDir DestDir *

You can also use xcopy /d, which will do the same:

xcopy /d SourceDir\* DestDir

Both commands can traverse folders if you provide the /S switch.
0
 
LVL 11

Assisted Solution

by:jgiordano
jgiordano earned 100 total points
ID: 33605006
create a batch file in notepad with something as simple as

cp c:\foldera\*.* c:\folderb\*.*
cp c:\foldera\*.* c:\folderc\*.*

schedule it through the windows scheduler
0
 
LVL 11

Expert Comment

by:jgiordano
ID: 33605010
you can also use windows synctoy http://www.microsoft.com/downloads/details.aspx?FamilyId=E0FC1154-C975-4814-9649-CCE41AF06EB7&displaylang=en

this program will sync folders for you and get pretty granular for a free tool. It also can be scheduled through windows scheduler.
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 11

Expert Comment

by:jgiordano
ID: 33605017
sorry the correct command is xcopy on windows not cp
0
 
LVL 6

Expert Comment

by:apresence
ID: 33605020
As an added note to Qlemo's comment, you can use the following robocopy switch to check for updates and do any additional copies "every 1 min or so":
/MOT:m :: MOnitor source; run again in m minutes Time, if changed.

Robocopy has a lot of powerful options.  Use robocopy /? to list them all.  For example, you might want to copy file ownership information in addition to the file contents.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 33605022
xcopy - as I told, but with /D, please. Without it will copy *all* existing files, no matter if changed or not.

SyncToy can do that task, but it is oversized for this particular case, and runs too long to call it every frew minutes.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 33605028
Really good point, apresence. RoboCopy can monitor itself for changes, no need for a scheduled task then.
0
 
LVL 1

Author Comment

by:masdf123
ID: 33605111
do I need to install xcopy? how does it keep running?
0
 
LVL 6

Expert Comment

by:apresence
ID: 33605346
masdf123, xcopy (and robocopy) are included with Server 2008.  They are command-line tools, so you have to start a command prompt to use them.

I really think robocopy is the better option.  If you run xcopy every minute it'll have to check the entire folder for changes each time.  I suspect you'll see your disk usage very high all the time.

Robocopy "monitors" the file system for changes only (Windows sends it a message to notify when something's changed... until then it waits idly), so it's not producing any disk activity unless something is changed.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 33605934
This time you are wrong. apresence. /MON does no more than check for changes using the modify time stamp of files. There is not much difference between issuing xcopy every x minutes and using RoboCopy /MON:x.
And as I have seen here on EE, /MON does *not* apply to subfolders, only to the "root" folder you provide. If you have to monitor subfolders, there needs to run a RoboCopy /MON for each subfolder.

Regarding performance and cpu load introduced - if you scan folders every minute, you can assume that is kept in cache all the time, so it should not be stressing that much.
0
 
LVL 1

Author Comment

by:masdf123
ID: 33607855
When I run this, do I leave the command prompt open? Does it run like a schedule or so?

Can I send the files to 2 different directory's as destination?
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 33607929
When you run RoboCopy, and it is finished, the DOS window is no longer required.
You can't send the files to 2 different locations. To do that, you need to run another xcopy or robocopy.
0
 
LVL 1

Author Comment

by:masdf123
ID: 33608036
When I use /mon:1.

Will it do the job?
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 33608042
As said, it will only apply to the root folder, and only for one destination. If you run two, one for each destination, and do not need to monitor subfolders, then /mon:1 will do.
0
 
LVL 1

Author Comment

by:masdf123
ID: 33608050
Does this run as a process? How do I cancel it?
0
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 400 total points
ID: 33608056
Each robocopy will run in a DOS box, which you can kill (and robocopy with it), or you press Ctrl-Break or Ctrl-C to stop.
0
 
LVL 1

Author Comment

by:masdf123
ID: 33608166
So I leave the command prompt open?

And if I logoff, it would close the dos prompt?
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 400 total points
ID: 33608182
Yes, and yes.
0
 
LVL 12
ID: 33622638
Masff123, you should use the robocopy command Qelmo gave you with the monitor option.  

However it looks liek you want this batch file/ command to run silently reguardless of peopel logging on or off the computer.

To accomplish this you should make the batch file/command a scheduled task running as an administrator on the computer; and schedule it to start every day at midnight, and set it to kill itself if still running at 11:59 PM so you don't miss any 1 minute iterations.  Obviously it woudl be best to have the task running on a server or other stable environment.
0
 
LVL 1

Author Closing Comment

by:masdf123
ID: 33785642
Solved
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

751 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