Rename a folder maintaining its content from a VB.NET Form

  • Thread starter Thread starter Robert M
  • Start date Start date
R

Robert M

Hello everybody,

Is it possible to rename a folder before showing it on a treeview on a
VB.NET form..The property .name is readonly..
can anybody help..

Thank u
 
Is it possible to rename a folder before showing it on a treeview on a
VB.NET form..The property .name is readonly..
can anybody help..

Check out Directory.Move()

John.
 
I am trying but it still does not work ..the code is as follow


For Each subDir In arSubs

Dim dirInfo As DirectoryInfo = New DirectoryInfo(subDir)

' do not show hidden folders

If (dirInfo.Attributes And FileAttributes.Hidden) = 0 Then

Dim subNode As TreeNode = New TreeNode(dirInfo.Name)

parentNode.Nodes.Add(subNode)

' Set colors based on Index property.

If (subNode.Index Mod 2 = 0) Then

subNode.BackColor = Color.LightPink

End If


End If

If dirInfo.Name = "m2" Then

dirInfo.MoveTo("m7")

End If

Next
 
* "Robert M said:
I am trying but it still does not work ..the code is as follow


For Each subDir In arSubs

Dim dirInfo As DirectoryInfo = New DirectoryInfo(subDir)

' do not show hidden folders

If (dirInfo.Attributes And FileAttributes.Hidden) = 0 Then

Dim subNode As TreeNode = New TreeNode(dirInfo.Name)

parentNode.Nodes.Add(subNode)

' Set colors based on Index property.

If (subNode.Index Mod 2 = 0) Then

subNode.BackColor = Color.LightPink

End If


End If

If dirInfo.Name = "m2" Then

dirInfo.MoveTo("m7")

End If

Next

Maybe you should rename it (for example using 'Directory.Move') _before_
showing it in the control.
 
Back
Top