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!

share friendly replacement for io.directory.move

Status
Not open for further replies.

edpatterson

IS-IT--Management
Feb 24, 2005
186
Is there a functionally equivalent for directory.move using share names?

directory.move(\\server\source\folder, \\server\destination\folder) throws a 'Source and destination path must have identical roots. Move will not work across volumes.' The shares are on the same volume but the app has no way of knowing that.

Ideas?

I am moving old home directories out of the tape path.

Ed
 
Here's a procedure that will copy the directory to a new location then delete the original:

Code:
    Private Sub MoveDirectory(ByVal SourcePath As DirectoryInfo, ByVal DestinationPath As DirectoryInfo)
        Dim SourceFiles As FileInfo()
        Dim SourceDirectories() As DirectoryInfo
        Dim strFileDestPath As String

        If Not DestinationPath.Exists Then
            DestinationPath.Create()
        End If

        SourceFiles = SourcePath.GetFiles

        For Each SourceFile As FileInfo In SourceFiles
            If DestinationPath.FullName.LastIndexOf("\") < DestinationPath.FullName.Length - 1 Then
                strFileDestPath = DestinationPath.FullName & "\" & SourceFile.Name
            Else
                strFileDestPath = DestinationPath.FullName & SourceFile.Name
            End If
            SourceFile.CopyTo(strFileDestPath)
        Next

        SourceDirectories = SourcePath.GetDirectories

        For Each SourceDirectory As DirectoryInfo In SourceDirectories
            MoveDirectory(SourceDirectory, New DirectoryInfo(Path.Combine(DestinationPath.FullName, SourceDirectory.Name)))
        Next


        System.IO.Directory.Delete(SourcePath.FullName, True)
    End Sub

Call it like this:

MoveDirectory(New DirectoryInfo("\\server\source\folder"), New DirectoryInfo("\\Twain\Share$\test\"))



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top