1 Viewing the contents of a folder
2 UI
3 Code
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.IO;7 usingSystem.Linq;8 usingSystem.Text;9 usingSystem.Threading.Tasks;Ten usingSystem.Windows.Forms; One A namespaceWindowsFormsApplication2 - { - Public Partial classForm1:form the { - PublicForm1 () - { - InitializeComponent (); + } - + Private voidForm1_Load (Objectsender, EventArgs e) A { at stringPath =@"l:\ folders created with programs"; - - //The recursion of the function is used. - showeveryfile (path, treeview1.nodes); - } - in Private voidShoweveryfile (stringpath, treenodecollection nodes) - { to //dires Storage is the absolute path to the folder + string[] Dires =directory.getdirectories (path); - for(inti =0; I < Dires. Length; i++) the { * //the name of the folder $ varnewnodes=nodes. ADD (Path.getfilename (dires[i));Panax Notoginseng //recursion of the function, appeared - Showeveryfile (Dires[i], newnodes.nodes); the } + A //when a function is applied to the deepest depths, it is called when it is ready to come out one layer at a time . the string[] files =directory.getfiles (path); + for(inti =0; I < files. Length; i++) - { $ nodes. ADD (Path.getfilename (files[i)); $ } - } - } the}
4 effects
See how the Iteration function works
1. Set a breakpoint on the line of code that calls the function that needs to be iterated
2, F5 run to the breakpoint
3, F11 a line of code, a row of the run.
4, observe the local Variables window and record the relevant parameters.
The iterative function is one layer deep, deep into the innermost layer, and then outward.
C#winform TreeView Simple Folder manager view files under Folders, files under sub-files