0
How do I get a file size in a treeview ?
I'm doing a project it's a file explorer with recursivity with the C:// rute , the directory file and subfiles are visible in the treeview I also have the method that gets the numbers of files but it still left the size of every file I tryed so many diferent things but it doesn't shows the size yet hope you could help me.
2 Answers
0
C++?
0
hi :) oh yes C# ! with a windows form here is the code :
private void Mostra_Click (object sender, EventArgs e) { ListDirectory(ĂrbolVista, "C://prueba"); }
private void ListDirectory (Treeview treeview.string hoja){ treeview. Nodes.Clear (); var rootDirectoryInfo=newDirectoryInfo(hoja); treeview. Nodes.Add (CreateDirrctoryNode (root DirectoryInfo)); }
private static TreeNode CreateDirectoryNode (DirectoryInfo directoryInfo ) {
var directoryNode = new TreeNode (directoryInfo.Name );
foreach (var directory in directoryInfo. GetDirectories () directoryNode.Nodes.Add (CreateDirectoryNode (directory));
foreach (var file in directoryInfo.GetFiles ()directoryNode. Nodes.Add (new TreeNode (file.Name));
return directoryNode ;
} //here I do the acciĂłn for obtein the numbers of files
private void InfoSize_Click (object sender ,Event Args e) {
ĂrbolVista. Path Separator = ".";
int myNodeCount= ĂrbolVista. Selected node. GetNodeCount (true);
decimal my ChildPercentage = ((decimal)myNodeCount/ (true))* 100;
MessageBox. Show ( ArbolVista. SelectedNode.FullPath+ " contiene+ myNodeCount.toString ()+"archivos. \n"+string.Format ("{0:###.##}", myChildPercentage)+"% del total de archivos en la carpeta raĂz. ");
}