Get filenames without path of a specific directory

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

    string fileName = @"C:\mydir\myfile.ext";
    string path = @"C:\mydir\";
    string result;
    
    result = Path.GetFileName(fileName);
    Console.WriteLine("GetFileName('{0}') returns '{1}'", 
    fileName, result);
    
    result = Path.GetFileName(path);
    Console.WriteLine("GetFileName('{0}') returns '{1}'", 
    path, result);
    

提交回复
热议问题