Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Strange IO.Directory.Move behavior

Strange IO.Directory.Move behavior

Scheduled Pinned Locked Moved Visual Basic
questiondata-structuresdebugginghelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brad Fackrell
    wrote on last edited by
    #1

    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 String

    selectedPath = 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 Sub

    Let 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 exits Private Sub renameFolder() the old folder re-appears. At this point the new folder and the old folder are present. Thanks Brad

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups