Click here to Skip to main content
Click here to Skip to main content

Zeta Folder XCOPY

, 26 Sep 2009
Rate this:
Please Sign up or sign in to vote.
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
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 has also teached programming to students at the local university.
 
In his free time, he does climbing, running and mountain biking. Recently he became a father of a cute boy.
 
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
Offline-Homepage-Baukasten

Comments and Discussions

 
GeneralMy vote of 5 Pinmembergduncan41121-Dec-12 7:22 
Generalthanks, and one probably naive question ... PinmemberBillWoodruff26-Sep-09 21:46 
GeneralRe: thanks, and one probably naive question ... PinsitebuilderUwe Keim26-Sep-09 22:00 
GeneralRe: thanks, and one probably naive question ... PinmemberBillWoodruff26-Sep-09 22:33 
GeneralRe: thanks, and one probably naive question ... PinsitebuilderUwe Keim26-Sep-09 23:00 
GeneralRe: thanks, and one probably naive question ... PinmemberBillWoodruff26-Sep-09 23:10 
GeneralSuggestion regarding Options PinmemberJason Vogel26-Sep-09 10:11 
GeneralRe: Suggestion regarding Options PinsitebuilderUwe Keim26-Sep-09 10:19 
GeneralRe: Suggestion regarding Options PinmemberJason Vogel26-Sep-09 10:28 
GeneralRe: Suggestion regarding Options PinsitebuilderUwe Keim26-Sep-09 10:37 
GeneralRe: Suggestion regarding Options [modified] PinmemberJason Vogel26-Sep-09 12:30 
Questionrobocopy? Pinmemberchristoph braendle26-Sep-09 6:58 
AnswerRe: robocopy? PinsitebuilderUwe Keim26-Sep-09 7:02 
Questionmultiple file/folder filters? PinmemberUnruled Boy26-Sep-09 1:49 
AnswerRe: multiple file/folder filters? PinsitebuilderUwe Keim26-Sep-09 2:31 
GeneralRe: multiple file/folder filters? PinmemberUnruled Boy26-Sep-09 4:06 

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.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 26 Sep 2009
Article Copyright 2009 by Uwe Keim
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid