DirectoryInfo.MoveTo "Across Volumes"

G

Guest

I haven't done a lot of file I/O in .NET and thought I had this figured out.

I am simply wanting to move a UNC-based directory path to a new path using
DirectoryInfo.

Example:

Source directory I want to move:
\\server\share1\MyDir

to:
\\server\share2\MyDir

I am attempting to do this via the following code:

Dim d As New DirectoryInfo(SrcDirectory)
d.MoveTo(TgtDirectory)

However this throws the error "Source and destination path must have
identical roots. Move will not work across volumes".

I understand the error as "\server\share2" and "\server\share1" represent
different roots. So my question is how, using .NET 2.0, do I move a
directory across volumes? This seems like it SHOULD be so simple. Is there
something I'm missing?

TIA.
 
G

Guest

I dont think Files dont have the same limitation so you would need to make
the desination directory, then move each file (got with
DirectoryInfo.GetFiles()) then delete the old Directory.
If move fails on files due to different roots, copy and delete each one.

I think the cause for the error is that the DirectoryMove function in
windows just changes MasterFileTable/FAT entries rather than shifts the data.

HTH

Ciaran O'Donnell
 
G

Guest

You've got to be kidding! Move each file one by one? :) This is .NET ...the
latest/greatest programming language on earth ...why is what should be so
easy/trivial so hard? I'll use the fso object if it comes down to that. To
have to move each file/directory one by one is pathetic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top