As I have mentioned in the previous blogs, I won't talk about anything here, so I can directly paste the code.
1. Control interpretation:
The FolderBrowserDialog control is used to display the "Browse folder" dialog box.
TextBox controls a ---- used to display the selected folder
A Button control ---- used to open the "Browse folder" dialog box
ListView controls one ---- used to display the subfolders and file information in the selected folder
2. instance code:
Private void button#click (object sender, EventArgs e) {listView1.Items. clear (); if (folderBrowserDialog1.ShowDialog () = DialogResult. OK) {textBox1.Text = folderBrowserDialog1.SelectedPath; // instantiate the DirectoryInfo object DirectoryInfo dinfo = new DirectoryInfo (textBox1.Text); // obtain all subdirectories and file types in the specified directory. FileSystemInfo [] fsinfos = dinfo. getFileSystemInfos (); foreach (FileSystemInfo fsinfo in fsinfos) {if (fsinfo is DirectoryInfo) // determine whether a folder exists {// use the obtained folder name to instantiate the DirectoryInfo object DirectoryInfo dirinfo = new DirectoryInfo (fsinfo. fullName); // Add the Folder Information listView1.Items for the ListView control. add (dirinfo. name); listView1.Items [listView1.Items. count-1]. subItems. add (dirinfo. fullName); listView1.Items [listView1.Items. count-1]. subItems. add (""); listView1.Items [listView1.Items. count-1]. subItems. add (dirinfo. creationTime. tow.datestring ();} else {// instantiate the FileInfo object FileInfo finfo = new FileInfo (fsinfo. fullName); // Add the file information listView1.Items for the ListView control. add (finfo. name); listView1.Items [listView1.Items. count-1]. subItems. add (finfo. fullName); listView1.Items [listView1.Items. count-1]. subItems. add (finfo. length. toString (); listView1.Items [listView1.Items. count-1]. subItems. add (finfo. creationTime. toShortDateString ());}}}}
3. Run:
Click Browse
After selecting a folder: