Strange IO.Directory.Move behavior
-
Can anybody tell me why the code below would execute
IO.Directory.Move
and then re-create the original folder name?Private Sub renameFolder()
Dim Prompt As String
Dim oldFolderName As String
Dim folderName As String
Dim selectedPath As String
Dim newPath As StringselectedPath = TreeView1.SelectedNode.FullPath ' get the full path of the selected node
oldFolderName = TreeView1.SelectedNode.Text ' get the name of the selectd node
Prompt = "Enter the new name for: " & oldFolderName ' ask for the new folder name
folderName = InputBox(Prompt, "Rename Folder", oldFolderName) ' load the name into the variable 'folderName'
newPath = selectedPath.Replace(oldFolderName, folderName) ' build the new path by replacing the old name with the new
IO.Directory.Move(selectedPath, newPath) ' remove the old directory
TreeView1.SelectedNode.Parent.Nodes.Add(folderName) ' add the new folder to the treeView
TreeView1.SelectedNode.Remove() ' remove the old node from the tree
End SubLet me explain what is happening; When I step through this code with the debugger it seems to execute perfectly. After
IO.Directory.Move(selectedPath, newPath)
executes, the old folder is gone and the and the new folder is present. The problem is that as the debugger exitsPrivate Sub renameFolder()
the old folder re-appears. At this point the new folder and the old folder are present. Thanks Brad