Requirement: Get the size of a folder or a remote computer within a reasonable timeframe.
WMI takes way too long to enumerate a directory and then calculate the size of its content's.
I attempted the following code however it says that its not a valid path
String Folder = Row["Location"].ToString();
String[] Files = Directory.GetFiles(@"\\" + Folder.Remove(0, 2) + @"\c$" + Folder, "*", SearchOption.AllDirectories);
long TotalFolderSize = 0;
foreach (String File in Files)
{
TotalFolderSize += new FileInfo(File).Length;
}
I'm not overly that great with PInvoke
, still pretty new to C#. I saw that Kernel32.dll
has some calls for files and disk but cannot find anything about folders or directories.
so the questions are
Is there a API/Function in C# that can get the size of a directory over the network.
Is there a PInvoke call that you can use to do this
What is the best way to do this?