Get filenames without path of a specific directory

前端 未结 8 1093
半阙折子戏
半阙折子戏 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:40

    Create a DirectoryInfo object, use a search pattern to enumerate, then treat it like an array.

    string filePath = "c:\Public\";
    DirectoryInfo apple = new DirectoryInfo(@filepath);
    foreach (var file in apple.GetFiles("*")
    {
       //do the thing
       Console.WriteLine(file)
    }
    

提交回复
热议问题