Interface layout
There is a "delete" button in the main interface design, which (ID) is btndelete. When the user selects the item to be deleted in the directory browsing, the delete work can be completed by clicking the button.
Code implementation
Double-click the Delete button in the design panel to add an event handler for it as follows:
Copy Code code as follows:
private void Btndelete_click (object sender, System.EventArgs e)
{
Deletethings (FileList.SelectedItem.Text);
}
private void Deletethings (string fullpath)
{
if (Fullpath.indexof (".") >0)//delete files
{
File.delete (FullPath);
Loaddir (Currentpath); Reload the current directory
}
else//Delete directory
{
Directory.delete (FullPath);
Loaddir (Currentpath); Reload the current directory
}
}
When you delete, you first determine whether the file or folder is selected. If it is a file, the File.delete () method is invoked, or the Directory.delete () method is invoked. After the deletion succeeds, the Loaddir () method is called to display the changed directory contents.