Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move Directories across volumes in .NET? 1

Status
Not open for further replies.

TimBiesiek

Programmer
Nov 3, 2004
151
AU
I am trying to move some directories and files across volumes using .NET.

The code I currently have is:

Code:
directory.move("C:\Test.txt","D:\Test050101.Txt")

Well, it's something to that effect, but it throws an exception as below:

System.IO.IOException: Source and destination path must have identical roots. Move will not work across volumes. at System.IO.Directory.Move(String sourceDirName, String destDirName)

I need to be able to move these files and directories across volumes to allow nightly backups of the data to be stored on our tape drives...

Any help would be much appreciated!

[banghead]
 
In view of the error message it looks as if you will have to copy and then delete

 
Hmmm, cheers.... will investigate down that road when our terminal server comes back online.... can't do any programming until then! Arghhhhhhh! [flush2]

Will let you know how I get on!
 
I don't have the IDE at home, but in the sample case, wouldn't you want file.move? Or to specify directories instead of file names?

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
[banghead]
 
Ah, sorry.... yes.... that would work for the example above....

However I have a whole directory I want to move, not just one file.... The directory could have any number of files in from 0 up to 500 odd.... needs to be backed up on a daily basis....
 
(Sorry, can't get exact code example at the mo, due to no access to terminal server!!)
 
Yet again Rick solves it.

I had a hierarchy

V:\
SL\
SL\
bin\
obj\
debug\
temp\
tepPE\

with a variety of files at each level.

I'm sure you recognise the structure

Sorry I didn't experiment before my inital reply, I just accepted you error and presumed.

'Dim d As New System.IO.DirectoryInfo("v:\sl")
'd.MoveTo("w:\sl")
Dim f As New System.IO.FileInfo("v:\sl")
f.MoveTo("w:\sl")

I tried the DirectoryInfo approach - it failed same error as yours
I tried the FileInfo approach - it worked.

 
Ok, cool... and that moves the entire directory structure (Files and all) to the W: drive?
 
Original properties of V:\SL
Size 2.05 mb
19 Files
6 Folders

Current properties of W:\SL
Size 2.05 mb
19 Files
6 Folders


I've loaded W:\sl\SL\sl.sln into the IDE and everything looks fine and W:\sl\SL\bin\exe crashes in exactly the same place that it did before!!

So the answer appears to be a definite yes.
 
Great! Thanks for that! Will let you know the outcome!!!
 
Finally got our Terminal Server back on line!

Tried the suggested code but it threw a different exception this time...

Code:
Dim TestDir As New System.IO.FileInfo("C:\Test")

TestDir.MoveTo("G:\")

Exception thrown was:

System.UnauthorizedAccessException: Access to the path is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.__Error.WinIOError()
at System.IO.FileInfo.MoveTo(String destFileName)
at Dialog_System_Utilities.FrmMain.TmrProcess_Tick(Object sender, EventArgs e) in \\admin1\lahar\Software\DIALOG Server Control Utilities\Dialog System Utilities - 20050406 VB.NET\FrmMain.vb:line 160


However, the G: drive (Network drive) is a valid drive, and I should have enough permissions to read, write and execute anything on this drive.....

[curse]
 
Looked up the UnauthorizedAccessException for the .moveto, and it says the following:

"destFileName is read-only or is a directory.
 
I'm not in VS at the moment, but the difference betweeen yours and mine is the trailing "\", which I didn't use. I don't know if that is significant. But it might be worth manually crreating a folder on G: such as G:\BackUpFromC and then trying:

Dim TestDir As New System.IO.FileInfo("C:\Test")

TestDir.MoveTo("G:\BackUpFromC")

If that doesn't work, then it may well be a permissions thing.

 
Thanks...

Tried what you mention above earthandfire, but it still shows same exception....

I tired simply moving it to "G:", "G:\Test", "G:\Test\", "G:\BackupFromC", "G:\BackupFromC\"

but still to no avail....
 
As I clicked "Submit", I just thought... Moving involves copying & deleting behind the scenes. Do you have Delete permissions on the source drive
 
Yip, just manually deleted the BackupFromC folder I created earlier....
 
You created BackupFromC on the target drive, can you delete from the source drive?
 
Yup, surely can.... Deleted the Test directory from C: drive....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top