MoveDirectory

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
 
N

Norm

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.
 
D

David C

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.
 
N

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
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top