简体   繁体   中英

get filenames from a directory without full path

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.

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);

使用lazyberezovsky的解决方案或使用提供“名称”属性的FileInfo类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM