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]
 
Last thing that I can think of. Do you need to delete the files/folders? Could you not just copy them?

If you really do have to move them, then it might be worth investigating good old DOS. When all else fails use a real operating system [smile]
 
Hmmm, will have to try copying and deleting me thinks....

Thanks for you help tho! Have a star for suggesting DOS!

[openup]
 
I've just had another couple of thoughts, although these are more likely confirm the problem rather than solve it.

I sometimes have to work on an Access .mde database running under Citrix on Terminal Server. If the change is small, then I've tried to make the change to the .mdb file and then recreate the .mde. I have full Admistrator rights on the Citrix server, but it always refuses to allow me to create the .mde and its always an access denied error. Whether this has any relevance, I don't know, but its something to consider.

The other thought was to do with .Net security. Are you running your program locally on the server, ie actually installed on and runnning on the server. If not .Net's security might be getting in the way. Again just something to think about.

Otherwise XCOPY & DEL (lifesavers).
 
Okey dokey, got around it in the end.... Have ended up creating the new directory, then copying all files across, then deleting old directory as below:

Code:
'This is in the main code process
Dim strFromDir, strToDir As String
strFromDir = "C:\Test\"
strToDir = "G:\Test\"
Directory.CreateDirectory(strToDir)
CopyDirectory(strFromDir, strToDir)
Directory.Delete(strFromDir, True)

'Function to move all files and subdirectories
Public Function CopyDirectory(ByVal source As String, ByVal destination As String)

    Dim currentDirectory As DirectoryInfo = New DirectoryInfo(source)
    Dim file As FileInfo

    'Copy Files individually
    For Each file In currentDirectory.GetFiles()
        file.CopyTo(Path.Combine(destination, file.Name))
    Next

    Dim di As DirectoryInfo

    'create sub directories if any
    For Each di In currentDirectory.GetDirectories()
        Dim subDirectory As String = Path.Combine(destination, di.Name)
        Directory.CreateDirectory(subDirectory)
        CopyDirectory(di.FullName, subDirectory)
    Next

End Function

Hope this is of help to someone!

[hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top