i want to create functions what get the folder size. I write small function:
private: unsigned long long GetDirectorySize(String^ path) {
unsigned long long size = 0;
DirectoryInfo^ diBase = gcnew DirectoryInfo(path);
if (!diBase->Exists) return 0;
array <FileInfo^>^ files;
array <FileSystemInfo^>^ files2;
try {
files = diBase->GetFiles("*", SearchOption::TopDirectoryOnly);
for each(FileInfo^ file in files) {
size += file->Length;
}
}
return size;
}
But sometimes function return exception. it is DirectoryNotFoundException and UnauthorizedAccessException i want to rewrite this function.that would function just missed a file or folder that caused this exception. How do this?