In a previous post I have asked how to get total # of files, folders and folder size. By the help of you guys, I was able to get the code and it runs fine. But I am having an issue. I am trying to develop an application that will connect to different servers and will get their data. All servers will have same user name and password, so connecting to them is not an issue. What I am seeing is when I run my code it takes 15-20 secs to return total # of files, folders, and size. But when I open the same folder in window's explorer (using UNC path)and click properties then the same folder returns data within couple of seconds. If anyone can let me know the reasons and ways to improve the following code then I will appreciate it.
Thanks
P.S: Does anyone of you know what to put in CODE tag to show it as either vb or C# code
Thanks
P.S: Does anyone of you know what to put in CODE tag to show it as either vb or C# code
Code:
Dim di As New DirectoryInfo(folderPath) Dim totalFiles As Integer = 0 Dim totalFolders As Integer = 0 Dim totalSizeMB As Double = 0 Dim innerDI As DirectoryInfo Dim tempFile As FileInfo totalFolders = di.GetDirectories("*", SearchOption.AllDirectories).Length totalFiles = di.GetFiles("*", SearchOption.AllDirectories).Length For Each innerDI In di.GetDirectories("*", SearchOption.AllDirectories) For Each tempFile In innerDI.GetFiles("*", SearchOption.TopDirectoryOnly) totalSizeMB += tempFile.Length Next Next
Comment