Click here to Skip to main content
Licence CPOL
First Posted 26 Sep 2009
Views 16,355
Downloads 179
Bookmarked 14 times

Zeta Folder XCOPY

By | 26 Sep 2009 | Article
A small class to perform basic XCOPY like operations from within C#
ZetaFolderXCopy

Introduction

During the process of moving some command scripts to a more robust solution that involved C# Script, I was in the need to replace several XCOPY calls with their equivalents in C#.

What I wanted to avoid is to simply start a CMD.EXE process and call the XCOPY command.

Instead I looked for a class/function in .NET/C# that can serve as a replacement. Although I found some solutions, none of them worked the way I wanted them.

Using the Code

So I decided to develop my own small solution that is no rocket science code but fulfills my requirements.

It has fewer features than XCOPY and is intended for copying folders (the original XCOPY works for both files and folders). In addition it is being designed to be used in a console environment (i.e., the operations are synchronous and blocking).

An example call looks like:

var options =
    new ZetaFolderXCopyOptions
        {
            FilesPattern = "*.*",
            RecurseFolders = true,
            CopyEmptyFolders = true,
            CopyHiddenAndSystemFiles = true,
            OverwriteExistingFiles = true,
            CopyOnlyIfSourceIsNewer = false,
            FoldersPattern = "*"
        }
        .AddExcludeSubStrings(
            "\\.svn\\",
            "\\_svn\\",
            "\\_Temporary\\" );

var xc = new ZetaFolderXCopy();
xc.Copy(
    sourceFolderPath,
    destinationFolderPath,
    options );

The full code consists of a single .CS file and can be downloaded from the top of this article.

Simply drop it into your solution/script and use it. 

Epilog

This article introduced a small class to do basic operations that XCOPY and ROBOCOPY do from within your own C# code.

As always, I would love to get your feedback, suggestions and enhancements. Feel free to drop me a note below in the discussions section of the article.

History

  • 2009-09-25 - First release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Uwe Keim

Chief Technology Officer
Zeta Producer Desktop CMS
Germany Germany

Member

Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He is also teached programming to students at the local university.
 
In his free time, he does climbing, running and mountain biking. You can watch him most of the day (and probably night) programming.
 
Some cool, free software from us:
 
Free Test Management Software - Intuitive, competitive, Test Plans. Download now!  
Homepage erstellen - Intuitive, very easy to use. Download now!  
Send large Files online for free by Email
Some random fun stuff in German


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalthanks, and one probably naive question ... PinmemberBillWoodruff21:46 26 Sep '09  
GeneralRe: thanks, and one probably naive question ... PinsitebuilderUwe Keim22:00 26 Sep '09  
GeneralRe: thanks, and one probably naive question ... PinmemberBillWoodruff22:33 26 Sep '09  
GeneralRe: thanks, and one probably naive question ... PinsitebuilderUwe Keim23:00 26 Sep '09  
GeneralRe: thanks, and one probably naive question ... PinmemberBillWoodruff23:10 26 Sep '09  
GeneralSuggestion regarding Options PinmemberJason Vogel10:11 26 Sep '09  
GeneralRe: Suggestion regarding Options PinsitebuilderUwe Keim10:19 26 Sep '09  
GeneralRe: Suggestion regarding Options PinmemberJason Vogel10:28 26 Sep '09  
GeneralRe: Suggestion regarding Options PinsitebuilderUwe Keim10:37 26 Sep '09  
GeneralRe: Suggestion regarding Options [modified] PinmemberJason Vogel12:30 26 Sep '09  
Questionrobocopy? Pinmemberchristoph braendle6:58 26 Sep '09  
AnswerRe: robocopy? PinsitebuilderUwe Keim7:02 26 Sep '09  
Questionmultiple file/folder filters? PinmemberUnruled Boy1:49 26 Sep '09  
AnswerRe: multiple file/folder filters? PinsitebuilderUwe Keim2:31 26 Sep '09  
GeneralRe: multiple file/folder filters? PinmemberUnruled Boy4:06 26 Sep '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 26 Sep 2009
Article Copyright 2009 by Uwe Keim
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid