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 Antworten
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. ");
}