string path = @"c:\MyFolder\MyFile.txt"; FileSystemInfo fileInfo = new FileInfo(path); Console.WriteLine($"File '{fileInfo.Name}' is {fileInfo.Length} bytes.");
string path = @"c:\MyFolder\"; DirectoryInfo directoryInfo = new DirectoryInfo(path); foreach (FileSystemInfo file in directoryInfo.GetFiles("*.*", SearchOption.AllDirectories)) { Console.WriteLine($"File '{file.Name}' is {file.Length} bytes."); }This code creates a DirectoryInfo object using the path of a directory, and then displays the name and size of all the files in the directory and its subdirectories. Package library: This class is a part of the .NET framework and does not require any external package or library.