Get filenames without path of a specific directory

前端 未结 8 1074
半阙折子戏
半阙折子戏 2020-12-13 16:44

How can I get all filenames of a directory (and its subdirectorys) without the full path? Directory.GetFiles(...) returns always the full path!

8条回答
  •  粉色の甜心
    2020-12-13 17:35

    Although several right answers are there for this questions, You may find this solution as:

    string[] files = Directory.EnumerateFiles("C:\Something", "*.*")
                     .Select(p => Path.GetFileName(p))
                     .Where(s => s.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase)).ToArray();
    

    Thanks

提交回复
热议问题