C # Small Explorer

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.