Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM Computer
13-May-2025To calculate the total size of all files in a directory, including all subdirectories, you can use
DirectoryInfoand recursively enumerate files usingEnumerateFiles()with theSearchOption.AllDirectoriesoption.Example: Calculate total size (in bytes)
Notes:
Directory.EnumerateFiles(...)is memory-efficient compared toGetFiles(...)because it streams results..Where(...).Optional: Handle exceptions (e.g., permission errors)
Wrap file access in try-catch if you expect restricted folders: