usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceSmall Explorer { Public classMyFile { Public floatFilelength {Get;Set; }//file Length (KB) Public stringFileName {Get;Set; }//file name Public stringFilePath {Get;Set; }//file path Public stringFileType {Get;Set; }//File Type }}
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingSystem.IO;namespaceSmall Explorer { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } TreeNode TN; Private voidForm1_Load (Objectsender, EventArgs e) { //retrieves the drive name of all logical drives on the computer. driveinfo[] di =driveinfo.getdrives (); foreach(DriveInfo Iteminchdi) {tn=NewTreeNode (item. Name); Tn. Tag=item. Name; Tv01. Nodes.Add (TN); } } //Click Bind File and folder information Private voidTv01_afterselect (Objectsender, TreeViewEventArgs e) {TreeNode tn=tv01. SelectedNode; Binginfo (TN); } Private voidBinginfo (TreeNode tn) {//Clearlvlist. Items.clear (); //Binding subdirectoriesDirectoryInfo dic =NewDirectoryInfo (TN. Tag.tostring ()); Directoryinfo[] Info=DiC. GetDirectories (); foreach(DirectoryInfo Iteminchinfo) {TreeNode temp=NewTreeNode (); Temp. Text=item. Name; Temp. Tag=item. FullName; Tn. Nodes.Add (temp); } //get list of files under directoryfileinfo[] FileInfo =DiC. GetFiles (); //defining generic Collection Store file informationlist<myfile> files =NewList<myfile>(); //Traverse file List foreach(FileInfo itinchFileInfo) {MyFile file=NewMyFile (); File. FileName=it. Name; File. Filelength=it. Length; File. FileType=it. Extension; File. FilePath=it. FullName; Files. ADD (file); } //bind to the ListView foreach(MyFile eminchfiles) {ListViewItem LV=NewListViewItem (em. FileName); Lv. SubItems.Add (em. Filelength.tostring ()); Lv. SubItems.Add (em. FileType); Lv. SubItems.Add (em. FilePath); Lvlist. Items.Add (LV); } } //Copy Private voidCopy Toolstripmenuitem_click (Objectsender, EventArgs e) { //decide whether to select if(Lvlist. SelectedItems. Count = =0) { return; } //Prompt user to select destination folderFolderBrowserDialog FBD =NewFolderBrowserDialog (); DialogResult result=FBD. ShowDialog (); //source file path stringSourcePath = Lvlist. selecteditems[0]. subitems[3]. Text; //Destination file path stringDespath =NULL; //if the target location is selected correctly, perform a copy operation if(result==DialogResult. OK) {Despath=FBD. SelectedPath; //Lvlist A ListView object that displays file informationDespath + ="\\"+ lvlist. selecteditems[0]. subitems[0]. Text; //Copying Filesfile.copy (SourcePath, Despath); MessageBox.Show ("Copy succeeded! "); } } //Delete Private voidDelete Toolstripmenuitem_click (Objectsender, EventArgs e) { stringDelectpath= lvlist. selecteditems[0]. SubItems [3]. Text; File.delete (Delectpath); MessageBox.Show ("Delete Success! "); } }}
C # Small Explorer