From e7ab25708926c595c441cbb0a5ec673285c3accc Mon Sep 17 00:00:00 2001 From: TidyCoder <157531579+Tidy-Coder@users.noreply.github.com> Date: Tue, 6 Aug 2024 22:34:47 +0100 Subject: [PATCH] Update functions.cs --- c#/functions.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/c#/functions.cs b/c#/functions.cs index d4d1bf7..486252e 100644 --- a/c#/functions.cs +++ b/c#/functions.cs @@ -79,5 +79,27 @@ bool clear(string tidyPath){ } return false; } + long sizeDirectory(DirectoryInfo tidyInfoHere){ + long tidyNumReturn = 0; + + foreach(FileInfo f in tidyInfoHere.GetFiles()){ + tidyNumReturn += f.Length; + } + foreach(DirectoryInfo infoIsHere in tidyInfoHere.GetDirectories()){ + tidyNumReturn += this.sizeDirectory(infoIsHere) + } + return tidyNumReturn + } + long size(string tidyPath){ + if(this.isFile(tidyPath)){ + return (new FileInfo(tidyPath)).Length; + } + else if(this.isFolder(tidyPath)){ + return this.sizeDirectory(new DirectoryInfo(tidyPath)); + } + else{ + return -1; + } + } } }