PDA

Click to See Complete Forum and Search --> : Directory Copy **SOLVED**


Sgt-Peppa
Nov 12th, 2003, 04:51 AM
I am really pi**#* , but maybe I just dont understand it correct.

In dot net there is a Directory.Move Function. There is also a directory.delete method.
But there is no Directory.Copy Function :confused:

I mean hey, if I have a delete and a copy, I can create my own move Function with these two methods. :mad:
Now I need to write my own copy function, that sucks. :(

Sometimes I just dont understand Micro... :confused:

But hey, maybe thats just me and there is a good explanation for that.


Take care, :wave:

Stephan

CornedBee
Nov 12th, 2003, 06:47 AM
This is indeeed fascinating. The examples table lists "Copy a directory" and sends the you to Directory overview. Only, there is no example of copying a directory there...

You could try File.Copy to copy the directory, but I doubt it will succeed.

Sgt-Peppa
Nov 12th, 2003, 08:04 AM
Heres a class I wrote that does the trick for my Purposes. Maybe someone else is interested in that:


public class CopyDirectory
{
string source;
string destination;

public CopyDirectory(string mySource, string myDestination)
{
if(source=="")
{
throw new Exception("Class CopyDirectory created an Exception, string source has no value!");
}
if(destination=="")
{
throw new Exception("Class CopyDirectory created an Exception, string destination has no value!");
}
source = mySource;
destination = myDestination;
Directory.CreateDirectory(destination + @"\" + source);
CopyThisFolder(source);

}
private void CopyThisFolder(string folder)
{
string [] items;
items = Directory.GetFileSystemEntries(folder);
foreach (string item in items)
{
if (Directory.Exists(item)==true)
{
Directory.CreateDirectory(destination + @"\" + item);
CopyThisFolder(item);
}
else
{
string thisFile = item.Substring(item.LastIndexOf(@"\",item.Length,item.Length),item.Length-(item.LastIndexOf(@"\",item.Length,item.Length)));
File.Copy(item,destination + @"\" + item, true);
}
}
}
}


Take Care,

Stephan

DeadEyes
Nov 12th, 2003, 01:34 PM
um why not try the DirectoryInfo class?
It's methods include:
Create()
Delete()
MoveTo()
CopyTo()

CornedBee
Nov 12th, 2003, 03:45 PM
CopyTo is not listed in the VS.Net 2003 reference. I already looked.

Doesn't mean it's not there though.

Sgt-Peppa
Nov 13th, 2003, 02:55 AM
Originally posted by DeadEyes
um why not try the DirectoryInfo class?
It's methods include:
Create()
Delete()
MoveTo()
CopyTo()

Have you tried that? Are you sure about that? My Visual Studio does not show that method! All relevant methods I have are :

CREATE();
CREATESUBDIRECTORY();
DELETE();
MOVETO();

No Copy method at all.

I am using NET FRAMEWORK v1.1.4322
and Visual Studion 2003 English version 7.1.3088

But maybe I am just to blind to find it
:blush:

Thanks all,


Stephan

dynamic_sysop
Nov 13th, 2003, 06:05 AM
there is no CopyTo() on the directoryinfo , that only exists on fileinfo :)

Sgt-Peppa
Nov 13th, 2003, 06:15 AM
Originally posted by dynamic_sysop
there is no CopyTo() on the directoryinfo , that only exists on fileinfo :)

Thanks, thats what I thought!
Yeah, I am not blind :D

But my small class does the trick for me.

Maybe I should send it to bill and ask him to implement it in the Framework :lol:

Thanks again for all your comments, :wave:

Take care

Stephan

DeadEyes
Nov 13th, 2003, 07:44 AM
Originally posted by dynamic_sysop
there is no CopyTo() on the directoryinfo , that only exists on fileinfo :)
Thanks for the correction. I was looking at a book that was talking about both classes and listed some methods, which I assumed applied to both classes.

CornedBee
Nov 13th, 2003, 08:35 AM
And damn well they should.