FileInfo fileInfo = new FileInfo(@"C:\MyFolder\MyFile.TXT"); string lowercaseFileName = fileInfo.Name.ToLower(); Console.WriteLine(lowercaseFileName); // Output: myfile.txt
string[] files = Directory.GetFiles(@"C:\MyFolder", "*.txt"); foreach (string file in files) { FileInfo fileInfo = new FileInfo(file); string lowercaseFileName = fileInfo.Name.ToLower(); Console.WriteLine(lowercaseFileName); // Output: the lowercase file name }In this example, the GetFiles() method is called on the Directory class to retrieve an array of all files in the C:\MyFolder directory that have a .txt extension. The resulting string array is then looped through, and for each file, a new FileInfo object is created. The ToLower() method is then called on the Name property to convert the file name to lowercase, and the resulting string is printed to the console. Package library: The System.IO namespace is part of the .NET Framework class library, which is included in the .NET Framework package.