Skip to content

Repository files navigation

logo

RoboSharp

image

RoboSharp is a .NET wrapper for the awesome Robocopy windows application.

Robocopy is a very extensive file copy application written by microsoft and included in modern versions of Windows. To learn more about Robocopy, visit the documentation page at http://technet.microsoft.com/en-us/library/cc733145.aspx.

RoboSharp came out of a need to manipulate Robocopy in a c# backup application that I was writing. It has helped me tremendously so I thought that I would share it! It exposes all of the switches available in RoboCopy as descriptive properties. With RoboSharp, you can subscribe to events that fire when files are processed, errors occur and even as the progress of a file copy changes. Another really nice feature of RoboSharp is that you can pause and resume a copy that is in progress which is a feature that I though was lacking in Robocopy.

In the project, you will find the RoboSharp library as well as a sample backup application that shows off many (but not all) of the options. If you like the project, please rate it!

Here is an example of how you would use RoboSharp:

publicvoidBackup(){RoboCommandbackup=newRoboCommand();// eventsbackup.OnFileProcessed+=backup_OnFileProcessed;backup.OnCommandCompleted+=backup_OnCommandCompleted;// copy optionsbackup.CopyOptions.Source=Source.Text;backup.CopyOptions.Destination=Destination.Text;backup.CopyOptions.CopySubdirectories=true;backup.CopyOptions.UseUnbufferedIo=true;// select optionsbackup.SelectionOptions.OnlyCopyArchiveFilesAndResetArchiveFlag=true;// retry optionsbackup.RetryOptions.RetryCount=1;backup.RetryOptions.RetryWaitTime=2;backup.Start();}voidbackup_OnFileProcessed(objectsender,FileProcessedEventArgse){Dispatcher.BeginInvoke((Action)(()=>{CurrentOperation.Text=e.ProcessedFile.FileClass;CurrentFile.Text=e.ProcessedFile.Name;CurrentSize.Text=e.ProcessedFile.Size.ToString();}));}voidbackup_OnCommandCompleted(objectsender,RoboCommandCompletedEventArgse){Dispatcher.BeginInvoke((Action)(()=>{MessageBox.Show("Backup Complete!");}));}

Extended Results:

See below examples on how to access the extended results where you can get total, copied, skipped, mismatch, failed and extra statistics for directories and files and bytes, as well as additional speed info e.g. bytes per sec and megabytes per minute

voidcopy_OnCommandCompleted(objectsender,RoboCommandCompletedEventArgse){Dispatcher.BeginInvoke((Action)(()=>{OptionsGrid.IsEnabled=true;ProgressGrid.IsEnabled=false;varresults=e.Results;Console.WriteLine("Files copied: "+results.FilesStatistic.Copied);Console.WriteLine("Directories copied: "+results.DirectoriesStatistic.Copied);Console.WriteLine("MegaBytesPerMin: "+results.SpeedStatistic.MegaBytesPerMin);}));}

or

varcmd=newRoboCommand();varresults=awaitcmd.StartAsync();// do something with results...

or

varcmd=newRoboCommand();varcopyTask=cmd.Start();copyTask.Wait();// be careful to avoid deadlocks here!varresults=cmd.GetResults();// do something with results...

or

varcmd=newRoboCommand();cmd.OnCommandCompleted+=(args)=>{varresults=args.Results;// do something with results...}
cmd.Start();

=======

Contributing to RoboSharp

First off, thanks! Please go through the guidelines.

About

RoboSharp is a .NET wrapper for the awesome Robocopy windows application.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages