Files size?
-
Hi, any idea how to calculate files size found in some folder??
string[] arSourceFiles = System.IO.Directory.GetFiles(MyDir);
arSourceFiles.(:confused:);
Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)
Try This.... foreach (string file in arSourceFiles) { FileInfo finfo = new FileInfo(file); int filesize = finfo.Length; // Length returns the size of file. }
-
Try This.... foreach (string file in arSourceFiles) { FileInfo finfo = new FileInfo(file); int filesize = finfo.Length; // Length returns the size of file. }
-
Hi, any idea how to calculate files size found in some folder??
string[] arSourceFiles = System.IO.Directory.GetFiles(MyDir);
arSourceFiles.(:confused:);
Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)
Hello, If you also whant to look in the folders of you main folder, you have to go threw it recursive! Like this:
private double GetFileSize(DirectoryInfo di, double currentsize) { double actsize = currentsize; FileInfo\[\] AllFiles = di.GetFiles(); DirectoryInfo\[\] AllDirectories = di.GetDirectories(); foreach(FileInfo fi in AllFiles) { actsize = actsize + fi.Length; } foreach(DirectoryInfo dinew in AllDirectories) { actsize = GetFileSize(dinew, actsize); } return actsize; }
I think there is some feature in .Net >1.1 which does that. Hope it helps! All the best, Martin
-
Hello, If you also whant to look in the folders of you main folder, you have to go threw it recursive! Like this:
private double GetFileSize(DirectoryInfo di, double currentsize) { double actsize = currentsize; FileInfo\[\] AllFiles = di.GetFiles(); DirectoryInfo\[\] AllDirectories = di.GetDirectories(); foreach(FileInfo fi in AllFiles) { actsize = actsize + fi.Length; } foreach(DirectoryInfo dinew in AllDirectories) { actsize = GetFileSize(dinew, actsize); } return actsize; }
I think there is some feature in .Net >1.1 which does that. Hope it helps! All the best, Martin
-
Martin# wrote:
I think there is some feature in .Net >1.1 which does that.
Actually it's just a new overload for the
GetFiles
method. http://msdn2.microsoft.com/en-us/library/ms143327(vs.80).aspx[^]