Reputation:
Is there any function to get filenames without path?
I use
Directory.GetFiles(directory)
And then i replace directory
with string.Empty
for each filename, but a GetFilenamesWithoutFullPath would be nice.
Upvotes: 2
Views: 1173
Reputation: 1256
Use lazyberezovsky's solution or use the FileInfo class that provides a "Name" property.
Upvotes: -1
Reputation: 236188
Use Path.GetFileName which returns file name and extension from full path
var files = Directory.GetFiles(directory).Select(f => Path.GetFileName(f));
Or even
var files = Directory.GetFiles(directory).Select(Path.GetFileName);
Upvotes: 6