Recurse through TreeView and create folders
up vote
0
down vote
favorite
I want to build a function to recurse through a treeview and create each folder on a harddrive. The code is working fine so far. Once it reaches the end of a node it jumps one level deeper. But whta I am missing here is a line of code to jump back to the upper folder to continue creating the other folders.
This is what I have so far:
Private Sub RecurseNodes(ByVal col As TreeNodeCollection)
For Each tn As TreeNode In col
Console.WriteLine(drive_letter & treefix & tn.Text)
If tn.Nodes.Count > 0 Then
treefix = treefix & tn.Text & ""
RecurseNodes(tn.Nodes)
End If
Next tn
End Sub
This is what my output looks like:
E:Auftraggeber Projektname 00000
E:Auftraggeber Projektname 00000Export
E:Auftraggeber Projektname 00000Material
E:Auftraggeber Projektname 00000MaterialOriginal
E:Auftraggeber Projektname 00000MaterialTranscodiert
E:Auftraggeber Projektname 00000MaterialFootage
E:Auftraggeber Projektname 00000MaterialGFX
E:Auftraggeber Projektname 00000MaterialSFX
E:Auftraggeber Projektname 00000MaterialSprecher
E:Auftraggeber Projektname 00000MaterialProjekt
E:Auftraggeber Projektname 00000MaterialMusik
and this is what the tree actually looks like:
So once the code gets to E:Auftraggeber Projektname 00000MaterialFootage, it should go back the upper folder to continue processing.
It is probably just a single line or two of code but I just can't figure it out.
Thanks for your help!
vb.net recursion treeview
add a comment |
up vote
0
down vote
favorite
I want to build a function to recurse through a treeview and create each folder on a harddrive. The code is working fine so far. Once it reaches the end of a node it jumps one level deeper. But whta I am missing here is a line of code to jump back to the upper folder to continue creating the other folders.
This is what I have so far:
Private Sub RecurseNodes(ByVal col As TreeNodeCollection)
For Each tn As TreeNode In col
Console.WriteLine(drive_letter & treefix & tn.Text)
If tn.Nodes.Count > 0 Then
treefix = treefix & tn.Text & ""
RecurseNodes(tn.Nodes)
End If
Next tn
End Sub
This is what my output looks like:
E:Auftraggeber Projektname 00000
E:Auftraggeber Projektname 00000Export
E:Auftraggeber Projektname 00000Material
E:Auftraggeber Projektname 00000MaterialOriginal
E:Auftraggeber Projektname 00000MaterialTranscodiert
E:Auftraggeber Projektname 00000MaterialFootage
E:Auftraggeber Projektname 00000MaterialGFX
E:Auftraggeber Projektname 00000MaterialSFX
E:Auftraggeber Projektname 00000MaterialSprecher
E:Auftraggeber Projektname 00000MaterialProjekt
E:Auftraggeber Projektname 00000MaterialMusik
and this is what the tree actually looks like:
So once the code gets to E:Auftraggeber Projektname 00000MaterialFootage, it should go back the upper folder to continue processing.
It is probably just a single line or two of code but I just can't figure it out.
Thanks for your help!
vb.net recursion treeview
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to build a function to recurse through a treeview and create each folder on a harddrive. The code is working fine so far. Once it reaches the end of a node it jumps one level deeper. But whta I am missing here is a line of code to jump back to the upper folder to continue creating the other folders.
This is what I have so far:
Private Sub RecurseNodes(ByVal col As TreeNodeCollection)
For Each tn As TreeNode In col
Console.WriteLine(drive_letter & treefix & tn.Text)
If tn.Nodes.Count > 0 Then
treefix = treefix & tn.Text & ""
RecurseNodes(tn.Nodes)
End If
Next tn
End Sub
This is what my output looks like:
E:Auftraggeber Projektname 00000
E:Auftraggeber Projektname 00000Export
E:Auftraggeber Projektname 00000Material
E:Auftraggeber Projektname 00000MaterialOriginal
E:Auftraggeber Projektname 00000MaterialTranscodiert
E:Auftraggeber Projektname 00000MaterialFootage
E:Auftraggeber Projektname 00000MaterialGFX
E:Auftraggeber Projektname 00000MaterialSFX
E:Auftraggeber Projektname 00000MaterialSprecher
E:Auftraggeber Projektname 00000MaterialProjekt
E:Auftraggeber Projektname 00000MaterialMusik
and this is what the tree actually looks like:
So once the code gets to E:Auftraggeber Projektname 00000MaterialFootage, it should go back the upper folder to continue processing.
It is probably just a single line or two of code but I just can't figure it out.
Thanks for your help!
vb.net recursion treeview
I want to build a function to recurse through a treeview and create each folder on a harddrive. The code is working fine so far. Once it reaches the end of a node it jumps one level deeper. But whta I am missing here is a line of code to jump back to the upper folder to continue creating the other folders.
This is what I have so far:
Private Sub RecurseNodes(ByVal col As TreeNodeCollection)
For Each tn As TreeNode In col
Console.WriteLine(drive_letter & treefix & tn.Text)
If tn.Nodes.Count > 0 Then
treefix = treefix & tn.Text & ""
RecurseNodes(tn.Nodes)
End If
Next tn
End Sub
This is what my output looks like:
E:Auftraggeber Projektname 00000
E:Auftraggeber Projektname 00000Export
E:Auftraggeber Projektname 00000Material
E:Auftraggeber Projektname 00000MaterialOriginal
E:Auftraggeber Projektname 00000MaterialTranscodiert
E:Auftraggeber Projektname 00000MaterialFootage
E:Auftraggeber Projektname 00000MaterialGFX
E:Auftraggeber Projektname 00000MaterialSFX
E:Auftraggeber Projektname 00000MaterialSprecher
E:Auftraggeber Projektname 00000MaterialProjekt
E:Auftraggeber Projektname 00000MaterialMusik
and this is what the tree actually looks like:
So once the code gets to E:Auftraggeber Projektname 00000MaterialFootage, it should go back the upper folder to continue processing.
It is probably just a single line or two of code but I just can't figure it out.
Thanks for your help!
E:Auftraggeber Projektname 00000
E:Auftraggeber Projektname 00000Export
E:Auftraggeber Projektname 00000Material
E:Auftraggeber Projektname 00000MaterialOriginal
E:Auftraggeber Projektname 00000MaterialTranscodiert
E:Auftraggeber Projektname 00000MaterialFootage
E:Auftraggeber Projektname 00000MaterialGFX
E:Auftraggeber Projektname 00000MaterialSFX
E:Auftraggeber Projektname 00000MaterialSprecher
E:Auftraggeber Projektname 00000MaterialProjekt
E:Auftraggeber Projektname 00000MaterialMusik
E:Auftraggeber Projektname 00000
E:Auftraggeber Projektname 00000Export
E:Auftraggeber Projektname 00000Material
E:Auftraggeber Projektname 00000MaterialOriginal
E:Auftraggeber Projektname 00000MaterialTranscodiert
E:Auftraggeber Projektname 00000MaterialFootage
E:Auftraggeber Projektname 00000MaterialGFX
E:Auftraggeber Projektname 00000MaterialSFX
E:Auftraggeber Projektname 00000MaterialSprecher
E:Auftraggeber Projektname 00000MaterialProjekt
E:Auftraggeber Projektname 00000MaterialMusik
vb.net recursion treeview
vb.net recursion treeview
asked 20 hours ago
max07
398
398
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
The simple solution in this case is to store the old value of the treefix
variable before changing it, then revert to it after the inner RecurseNodes()
call has exited:
If tn.Nodes.Count > 0 Then
Dim currentPath As String = treefix
treefix = treefix & tn.Text & ""
RecurseNodes(tn.Nodes)
treefix = currentPath
End If
Though to avoid having to use class level variables, the more sustainable solution is to just pass the current path to your method. Also, do prefer Path.Combine()
when working with paths in general:
Private Sub RecurseNodes(ByVal col As TreeNodeCollection, ByVal currentDirectory As String)
For Each tn As TreeNode In col
Dim currentPath As String = Path.Combine(currentDirectory, tn.Text)
Console.WriteLine(currentPath)
If tn.Nodes.Count > 0 Then
RecurseNodes(tn.Nodes, currentPath)
End If
Next tn
End Sub
Example usage:
RecurseNodes(TreeView1.Nodes, "E:Auftraggeber Projektname 00000")
This is exactly what I needed. Passing the current path was a simple, but great idea. Thanks!
– max07
18 hours ago
@max07 : Glad I could help! Happy coding!
– Visual Vincent
18 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
The simple solution in this case is to store the old value of the treefix
variable before changing it, then revert to it after the inner RecurseNodes()
call has exited:
If tn.Nodes.Count > 0 Then
Dim currentPath As String = treefix
treefix = treefix & tn.Text & ""
RecurseNodes(tn.Nodes)
treefix = currentPath
End If
Though to avoid having to use class level variables, the more sustainable solution is to just pass the current path to your method. Also, do prefer Path.Combine()
when working with paths in general:
Private Sub RecurseNodes(ByVal col As TreeNodeCollection, ByVal currentDirectory As String)
For Each tn As TreeNode In col
Dim currentPath As String = Path.Combine(currentDirectory, tn.Text)
Console.WriteLine(currentPath)
If tn.Nodes.Count > 0 Then
RecurseNodes(tn.Nodes, currentPath)
End If
Next tn
End Sub
Example usage:
RecurseNodes(TreeView1.Nodes, "E:Auftraggeber Projektname 00000")
This is exactly what I needed. Passing the current path was a simple, but great idea. Thanks!
– max07
18 hours ago
@max07 : Glad I could help! Happy coding!
– Visual Vincent
18 hours ago
add a comment |
up vote
2
down vote
accepted
The simple solution in this case is to store the old value of the treefix
variable before changing it, then revert to it after the inner RecurseNodes()
call has exited:
If tn.Nodes.Count > 0 Then
Dim currentPath As String = treefix
treefix = treefix & tn.Text & ""
RecurseNodes(tn.Nodes)
treefix = currentPath
End If
Though to avoid having to use class level variables, the more sustainable solution is to just pass the current path to your method. Also, do prefer Path.Combine()
when working with paths in general:
Private Sub RecurseNodes(ByVal col As TreeNodeCollection, ByVal currentDirectory As String)
For Each tn As TreeNode In col
Dim currentPath As String = Path.Combine(currentDirectory, tn.Text)
Console.WriteLine(currentPath)
If tn.Nodes.Count > 0 Then
RecurseNodes(tn.Nodes, currentPath)
End If
Next tn
End Sub
Example usage:
RecurseNodes(TreeView1.Nodes, "E:Auftraggeber Projektname 00000")
This is exactly what I needed. Passing the current path was a simple, but great idea. Thanks!
– max07
18 hours ago
@max07 : Glad I could help! Happy coding!
– Visual Vincent
18 hours ago
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
The simple solution in this case is to store the old value of the treefix
variable before changing it, then revert to it after the inner RecurseNodes()
call has exited:
If tn.Nodes.Count > 0 Then
Dim currentPath As String = treefix
treefix = treefix & tn.Text & ""
RecurseNodes(tn.Nodes)
treefix = currentPath
End If
Though to avoid having to use class level variables, the more sustainable solution is to just pass the current path to your method. Also, do prefer Path.Combine()
when working with paths in general:
Private Sub RecurseNodes(ByVal col As TreeNodeCollection, ByVal currentDirectory As String)
For Each tn As TreeNode In col
Dim currentPath As String = Path.Combine(currentDirectory, tn.Text)
Console.WriteLine(currentPath)
If tn.Nodes.Count > 0 Then
RecurseNodes(tn.Nodes, currentPath)
End If
Next tn
End Sub
Example usage:
RecurseNodes(TreeView1.Nodes, "E:Auftraggeber Projektname 00000")
The simple solution in this case is to store the old value of the treefix
variable before changing it, then revert to it after the inner RecurseNodes()
call has exited:
If tn.Nodes.Count > 0 Then
Dim currentPath As String = treefix
treefix = treefix & tn.Text & ""
RecurseNodes(tn.Nodes)
treefix = currentPath
End If
Though to avoid having to use class level variables, the more sustainable solution is to just pass the current path to your method. Also, do prefer Path.Combine()
when working with paths in general:
Private Sub RecurseNodes(ByVal col As TreeNodeCollection, ByVal currentDirectory As String)
For Each tn As TreeNode In col
Dim currentPath As String = Path.Combine(currentDirectory, tn.Text)
Console.WriteLine(currentPath)
If tn.Nodes.Count > 0 Then
RecurseNodes(tn.Nodes, currentPath)
End If
Next tn
End Sub
Example usage:
RecurseNodes(TreeView1.Nodes, "E:Auftraggeber Projektname 00000")
answered 18 hours ago
Visual Vincent
14.9k51947
14.9k51947
This is exactly what I needed. Passing the current path was a simple, but great idea. Thanks!
– max07
18 hours ago
@max07 : Glad I could help! Happy coding!
– Visual Vincent
18 hours ago
add a comment |
This is exactly what I needed. Passing the current path was a simple, but great idea. Thanks!
– max07
18 hours ago
@max07 : Glad I could help! Happy coding!
– Visual Vincent
18 hours ago
This is exactly what I needed. Passing the current path was a simple, but great idea. Thanks!
– max07
18 hours ago
This is exactly what I needed. Passing the current path was a simple, but great idea. Thanks!
– max07
18 hours ago
@max07 : Glad I could help! Happy coding!
– Visual Vincent
18 hours ago
@max07 : Glad I could help! Happy coding!
– Visual Vincent
18 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265946%2frecurse-through-treeview-and-create-folders%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password