|
|
Nice. Mix in AlphaFS (http://alphafs.codeplex.com) for long path support and you've got a pretty good robocopy clone
|
|
|
|
|
Hi Uwe,
5 !
Many thanks for this fine example of production code ! fyi (no surprise) : it compiles and works fine in VS 2010 against FrameWork 4.0 in a WinForms project. The usual gotchas can occur if you are copying to some location with a long file path name, and the new file name would exceed the length limit (get ready to write to the root level of a drive if needed ?).
One thing that caught my eye studying your code was the place in the invocation example where you create a new instance of the ZetaFolderXCopyOptions class passing in a {} delimited set of default parameter names and values :
var options = new ZetaFolderXCopyOptions
{
FilesPattern = "*.*",
RecurseFolders = true,
CopyEmptyFolders = true,
CopyHiddenAndSystemFiles = true,
OverwriteExistingFiles = true,
CopyOnlyIfSourceIsNewer = false,
FoldersPattern = "*"
}
.AddExcludeSubStrings(
"\\.svn\\",
"\\_svn\\",
"\\_Temporary\\" );
I am familiar with optional parameter lists, setting properties in the constructor call, and automatic properties and such, but what did surprise me was the use of the dot after the closing curly brace that then, apparently, invokes a call to AddExcludeSubStrings : that's a usage I haven't seen before, and that's baffling : well back to Troelsen and Richter, and Liberty [or, worst case, MSDN] for me
My "C# mental scanning engine" kept looking in vain, for the required () after the use of 'New !
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
Hehe, thank you very much, Bill!
What helps me tremendously whith the new syntax capabilites of C# is to use the ReSharper[^] plug-in for VS.NET which suggests most of the new syntax automatically.
The .AddExcludeSubStrings came to my mind when I read about the idea of Fluent interface [^] design which I first discovered in the tweetsharp[^] project over at Google Code. I really do like the idea, it is very readable for me.
Thanks again for your kind words and voting!
Cheers
Uwe
|
|
|
|
|
Hi Uwe,
Thanks for the prompt response, and the links to Wiki and Google Code !
While examining what appeared to me be a strange meta-violation of object construction (as the mind of Bill dimly understood it) ... I had looked at your code for AddExcludeStrings and AddIncludeStrings, and puzzled over what the fact they returned 'this was doing, exactly. And I had thought : how can they be called, when they are not static, and depend (assumption) on being part of an instance of a class ? : it seemed like you were "getting away" with calling a public non-static method before the class was really fully "baked."
Finding things like this is like "catnip" for me (do German cats get "catnip" ?).
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
Thanks, Bill.
Since I own a dog[^] not a cat, I am rather unaware of those "cat" things .
|
|
|
|
|
Hi Uwe,
Indeed, one can "own" a dog, but a cat is a being who grants a lucky human the privilege of taking care of his or her celestial form : it would be more accurate to say "my cat owns me"
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
Instead of ...
new ZetaFolderXCopyOptions
{
FilesPattern = "*.*",
RecurseFolders = true,
CopyEmptyFolders = true,
CopyHiddenAndSystemFiles = true,
OverwriteExistingFiles = true,
CopyOnlyIfSourceIsNewer = false,
FoldersPattern = "*"
}
how about...
ZetaFolderXCopyOptions zetaOptions = new ZetaFolderXCopyOptions();
zetaOptions.RecurseFolders = true;
zetaOptions.CopyEmptyFolders = true;
...
This approach would allow Intellisense to "type" out the options and validate the "value" and compile time.
Just an idea,
jaso n
|
|
|
|
|
Erm... Are you kidding?
What you suggest is the same in terms of resulting MSIL and IntellIsense.
So to be honest I do not get your point. This is even allowed if you target the .NET 2.0 Runtime when using inside VS.NET 2008, since the 3.5 Compiler generates 2.0 code from this, if advised.
|
|
|
|
|
To be honest, both approaches should work in my opinion.
I like my "style" because, then I don't have to lookup the list of options. I can just type
object. and see a pop-up list. That's all. I know that the "default" approach [yours] is faster and more explicit. It also assumes that the Developer is knowledgeable about the options list. Call me lazy then. I like the popup style because I make fewer typing errors, and I tend to notice more of the available functionality.
Just a thought, not a complaint. Regardless, I like what you did.
Jason
|
|
|
|
|
Thanks, Jason.
I am using the ReSharper plug-in for VS.NET 2008. From what I see, the IntelliSense is just as well for both approaches.
Maybe the standard Microsoft IntelliSense is not capable of handling the "new" style?
|
|
|
|
|
Learned something today...
I use both VS 2005 and VS 2008. Unfortunately, most of my time is spent in VS 2005 b/c of work. Anyway, I took your code and back-ported to 2005 [minor changes only (replace "var" with actuals)].
In 2005, you can't [at least to my knowledge, get this construct to work [in any variation)...
var options = new ZetaFolderXCopyOptions
{
FilesPattern = "*.*",
RecurseFolders = true,
CopyEmptyFolders = true,
CopyHiddenAndSystemFiles = true,
OverwriteExistingFiles = true,
CopyOnlyIfSourceIsNewer = false,
FoldersPattern = "*"
}
.AddExcludeSubStrings(
"\\.svn\\",
"\\_svn\\",
"\\_Temporary\\" );
So hence, I know why I'm used to my "style". ... not enough time in VS 2008.
Interesting exercise.
Thanks,
Jason
modified on Saturday, September 26, 2009 7:10 PM
|
|
|
|
|
what is wrong with robocopy? it is quite powerful in my opinion
why not doing a nice c# wrapping class?
|
|
|
|
|
Yes, I am doing this currently with a VBScript wrapper.
As I said in the introduction, I wanted to have a "native" solution, not just a collection of CMD.EXE calles.
The main reason was to have a better control over the includes and excludes and to have all output messages in one place (frees me from capturing STDIN/STDERR).
So ROBOCOPY is fine, but I wanted to have more control
|
|
|
|
|
hi, does this code support multiple file/folder filters?
for example:
*.cs|*.csproj|*.sln
Regards,
unruledboy_at_gmail_dot_com
http://www.xnlab.com
|
|
|
|
|
Yes, luckily it does
Thanks for asking!
Cheers
Uwe
|
|
|
|
|
i miss xcopy so much
Regards,
unruledboy_at_gmail_dot_com
http://www.xnlab.com
|
|
|
|
|