Private void button2_click (Object sender, eventargs E)
{
Dirdg (treeview1.nodes. Add (@ "F:/my projects", "My Projects "));
}
// All directory files obtained as nodes
Void dirdg (treenode Tn)
{
Try
{
Foreach (string STR in directory. getdirectories (TN. Name ))
{
Dirdg (TN. nodes. Add (STR, path. getfilenamewithoutextension (STR )));
}
}
Catch
{}
}
Private void button3_click (Object sender, eventargs E)
{
Listview1.items. Clear ();
// Retrieve the file under the traversal node and add it to listviewitem.
Foreach (string STR in directory. getdirectories
(Treeview1.selectednode. Name ))
{
Listviewitem LVI = listview1.items. Add (STR,
Path. getfilenamewithoutextension (STR), 0 );
// Obtain a list of details
LVI. subitems. Add (directory. getlastwritetime (STR). tostring ("yyyy Year mm
Dd "));
LVI. subitems. Add ("folder ");
LVI. subitems. Add (getsize (STR). tostring ());
}
// Obtain all objects
Foreach (string STR in directory. getfiles (treeview1.selectednode. Name ))
{
Listviewitem LVI = listview1.items. Add (STR, path. getfilename (STR ),
0 );
LVI. subitems. Add (file. getlastwritetime (STR). tostring ("YYYY mm dd
"));
LVI. subitems. Add (path. getextension (STR ));
LVI. subitems. Add (New fileinfo (STR). length. tostring ());
}
}
// Obtain the file size
Long getsize (string path)
{
Long Len = 0;
Foreach (string STR in directory. getdirectories (PATH ))
{
Len = getsize (STR );
}
Long Len = 0;
Foreach (string STR in directory. getfiles (PATH ))
{
Fileinfo Fi = new fileinfo (STR );
Len + = Fi. length;
}
Return Len + Len;
}
Private void combobox#selectedindexchanged (Object sender, eventargs E)
{
Listview1.view = (View) enum. parse (typeof (view ),
Combobox1.selecteditem. tostring ());
}
Private void form1_load (Object sender, eventargs E)
{
Combobox1.datasource = enum. getnames (typeof (View ));
}
Private void listview1_click (Object sender, eventargs E)
{
}
Private void listview1_doubleclick (Object sender, eventargs E)
{
String Path = listview1.selecteditems [0]. Name;
If (! Path. hasextension (PATH ))
{
Listview1.items. Clear ();
Foreach (string STR in directory. getdirectories (PATH ))
{
Listviewitem LVI = listview1.items. Add (STR,
Path. getfilenamewithoutextension (STR), 0 );
LVI. subitems. Add (directory. getlastwritetime (STR). tostring ("yyyy
MM dd "));
LVI. subitems. Add ("folder ");
LVI. subitems. Add (getsize (STR). tostring ());
}
}
Else
{// Directly open the file with the extension
Process. Start (PATH );
}
}