Reputation: 147
I have a path D:\myfolder1\mysubfolder I want to move the mysubfolder to the root(D:) Here is the code I am trying to use which gives me an error saying invalid parameter.
Public Sub Movefolder()
Dim listFolders() As String = Directory.GetDirectories("D:\myfolder1")
Dim curf As String
For Each curf In listFolders 'listfolders(1) would be the mysubfolder
Dim DirInfo As New System.IO.DirectoryInfo(curf)
Directory.Move(curf, "D:\") 'This is where I get the error
Next
End Sub
Can anybody point out where I am doing wrong or is there a more easier or atleast another way to it??
Upvotes: 2
Views: 5784
Reputation: 20770
According to the docs, the destination path must include the new name of the file or directory you are moving.
As you already retrieve the DirectoryInfo
for the folder being moved, you can use its Name
property to get the name of the directory you are moving, which you can then append to the destination path:
For Each curf In listFolders '// listfolders(1) would be the mysubfolder
Dim DirInfo As New System.IO.DirectoryInfo(curf)
Directory.Move(curf, Path.Combine("D:\", DirInfo.Name))
Next
Upvotes: 4