How do I retrieve all filenames matching a pattern in a directory? I tried this but it returns the full path instead of the filename.
Directory.GetFiles (path, "*.txt")
Do I have to manually crop the directory path off of the result? It's easy but maybe there is an even simpler solution :)
Assuming you're using C#, the DirectoryInfo class will be of more use to you:
The FileInfo class contains a property
Name
which returns the name without the path.See the DirectoryInfo documentation and the FileInfo documentation for more information.
You can use the following code to obtain the filenames:
Try this if it is what you want
Try this
Use Path.GetFileName with your code:
Another solution: