Im looking for a way to read ALL txt files in a directory path without their extensions into an array. Ive looked through the path.getFileNameWithoutExtension but that only returns one file. I want all the *.txt file names from a path i specify
THanks
Directory.GetFiles(myPath, "*.txt")
.Select(Path.GetFileNameWithoutExtension)
.Select(p => p.Substring(1)) //per comment
Something like:
String[] fileNamesWithoutExtention =
Directory.GetFiles(@"C:\", "*.txt")
.Select(fileName => Path.GetFileNameWithoutExtension(fileName))
.ToArray();
Should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With