MoveDirectory

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

I am using the MoveDirectory method to move a folder and all of its
subfolders and files to another location but it does not work. It only
copies the source to the destination. Is there a method that will
physically move the designated folder, subfolders and files from source to
destination? Below is my code. Thanks.

David

strListFolderPath = strListFolderPath & strAddress
strListFolderPath = Server.MapPath(strListFolderPath)

strExpFolderPath = strExpFolderPath & strAddress
strExpFolderPath = Server.MapPath(strExpFolderPath)

If
My.Computer.FileSystem.DirectoryExists(strListFolderPath) = True Then
'Move all current listings folders to the expired
listing folder
My.Computer.FileSystem.MoveDirectory(strListFolderPath,
strExpFolderPath, True)
txtMsg.Text += "The current listings folders were
moved to the EXPIRED AND DEAD LISTINGS folder."
If
My.Computer.FileSystem.DirectoryExists(strExpFolderPath) = False Then
'No current expired folder exists for the
listing so create it
My.Computer.FileSystem.CreateDirectory(strExpFolderPath)
End If

End If
 
I am using the MoveDirectory method to move a folder and all of its
subfolders and files to another location but it does not work. It only
copies the source to the destination.  Is there a method that will
physically move the designated folder, subfolders and files from source to
destination?  Below is my code.  Thanks.

David

                    strListFolderPath = strListFolderPath & strAddress
                    strListFolderPath = Server.MapPath(strListFolderPath)

                    strExpFolderPath = strExpFolderPath & strAddress
                    strExpFolderPath = Server.MapPath(strExpFolderPath)

                    If
My.Computer.FileSystem.DirectoryExists(strListFolderPath) = True Then
                        'Move all current listings folders to the expired
listing folder
                        My.Computer.FileSystem.MoveDirectory(strListFolderPath,
strExpFolderPath, True)
                        txtMsg.Text += "The current listings folders were
moved to the EXPIRED AND DEAD LISTINGS folder."
                        If
My.Computer.FileSystem.DirectoryExists(strExpFolderPath) = False Then
                            'No current expired folder exists for the
listing so create it
                            My.Computer.FileSystem.CreateDirectory(strExpFolderPath)
                        End If

                    End If

The My namespace is a holdover from VB. I would suggest using
System.IO.Directory instead. I just ran a quick test with
System.IO.Directory.Move() and it worked as expected.
 
I am using the MoveDirectory method to move a folder and all of its
subfolders and files to another location but it does not work. It only
copies the source to the destination.  Is there a method that will
physically move the designated folder, subfolders and files from source to
destination?  Below is my code.  Thanks.

David

                    strListFolderPath = strListFolderPath & strAddress
                    strListFolderPath = Server.MapPath(strListFolderPath)

                    strExpFolderPath = strExpFolderPath & strAddress
                    strExpFolderPath = Server.MapPath(strExpFolderPath)

                    If
My.Computer.FileSystem.DirectoryExists(strListFolderPath) = True Then
                        'Move all current listings folders to the expired
listing folder
                        My.Computer.FileSystem.MoveDirectory(strListFolderPath,
strExpFolderPath, True)
                        txtMsg.Text += "The current listings folders were
moved to the EXPIRED AND DEAD LISTINGS folder."
                        If
My.Computer.FileSystem.DirectoryExists(strExpFolderPath) = False Then
                            'No current expired folder exists for the
listing so create it
                            My.Computer.FileSystem.CreateDirectory(strExpFolderPath)
                        End If

                    End If

The My namespace is a holdover from VB. I would suggest using
System.IO.Directory instead. I just ran a quick test with
System.IO.Directory.Move() and it worked as expected.
 
It didn't work. I was trying to move from one server to another and it
failed saying "Source and destination path must have identical roots. Move
will not work across volumes."

David
I am using the MoveDirectory method to move a folder and all of its
subfolders and files to another location but it does not work. It only
copies the source to the destination. Is there a method that will
physically move the designated folder, subfolders and files from source to
destination? Below is my code. Thanks.

David

strListFolderPath = strListFolderPath & strAddress
strListFolderPath = Server.MapPath(strListFolderPath)

strExpFolderPath = strExpFolderPath & strAddress
strExpFolderPath = Server.MapPath(strExpFolderPath)

If
My.Computer.FileSystem.DirectoryExists(strListFolderPath) = True Then
'Move all current listings folders to the expired
listing folder
My.Computer.FileSystem.MoveDirectory(strListFolderPath,
strExpFolderPath, True)
txtMsg.Text += "The current listings folders were
moved to the EXPIRED AND DEAD LISTINGS folder."
If
My.Computer.FileSystem.DirectoryExists(strExpFolderPath) = False Then
'No current expired folder exists for the
listing so create it
My.Computer.FileSystem.CreateDirectory(strExpFolderPath)
End If

End If

The My namespace is a holdover from VB. I would suggest using
System.IO.Directory instead. I just ran a quick test with
System.IO.Directory.Move() and it worked as expected.
 
It didn't work. I was trying to move from one server to another and it
failed saying "Source and destination path must have identical roots. Move
will not work across volumes."

David
I am using the MoveDirectory method to move a folder and all of its
subfolders and files to another location but it does not work. It only
copies the source to the destination. Is there a method that will
physically move the designated folder, subfolders and files from source to
destination? Below is my code. Thanks.

David

strListFolderPath = strListFolderPath & strAddress
strListFolderPath = Server.MapPath(strListFolderPath)

strExpFolderPath = strExpFolderPath & strAddress
strExpFolderPath = Server.MapPath(strExpFolderPath)

If
My.Computer.FileSystem.DirectoryExists(strListFolderPath) = True Then
'Move all current listings folders to the expired
listing folder
My.Computer.FileSystem.MoveDirectory(strListFolderPath,
strExpFolderPath, True)
txtMsg.Text += "The current listings folders were
moved to the EXPIRED AND DEAD LISTINGS folder."
If
My.Computer.FileSystem.DirectoryExists(strExpFolderPath) = False Then
'No current expired folder exists for the
listing so create it
My.Computer.FileSystem.CreateDirectory(strExpFolderPath)
End If

End If

The My namespace is a holdover from VB. I would suggest using
System.IO.Directory instead. I just ran a quick test with
System.IO.Directory.Move() and it worked as expected.
 
It didn't work. I was trying to move from one server to another and it
failed saying "Source and destination path must have identical roots. Move
will not work across volumes."







The My namespace is a holdover from VB. I would suggest using
System.IO.Directory instead. I just ran a quick test with
System.IO.Directory.Move() and it worked as expected.

Thats because you can't move a directory across volumes. This is due
to how the filesystem itself works. When you call Directory.Move() it
does not actually copy the files and then delete the original one. It
just changes the entry in the the Master File Table of that volume to
point to the new location. This is, of course, impossible to do across
volumes.

Here's a solution:
http://www.lmgtfy.com/?q=Source+and...ical+roots.+Move+will+not+work+across+volumes

Norm
 
It didn't work. I was trying to move from one server to another and it
failed saying "Source and destination path must have identical roots. Move
will not work across volumes."







The My namespace is a holdover from VB. I would suggest using
System.IO.Directory instead. I just ran a quick test with
System.IO.Directory.Move() and it worked as expected.

Thats because you can't move a directory across volumes. This is due
to how the filesystem itself works. When you call Directory.Move() it
does not actually copy the files and then delete the original one. It
just changes the entry in the the Master File Table of that volume to
point to the new location. This is, of course, impossible to do across
volumes.

Here's a solution:
http://www.lmgtfy.com/?q=Source+and...ical+roots.+Move+will+not+work+across+volumes

Norm
 
Back
Top