I have the following code:
string[] files = Directory.GetFiles(@"C:\Notes", "*.txt", SearchOption.TopDirectoryOnly);
foreach(string file in files)
When I check the contents of file it has the directory path and extension. Is there a way I can just get the filename out of that?
You can use the
FileInfoclass:If you want just the file name – quick and simple – use
Path: