How to get file names from the directory, not the entire path

后端 未结 4 630
别跟我提以往
别跟我提以往 2020-12-09 08:51

I am using the below method to get the file names. But it returns the entire path and I don\'t want to get the entire path. I want only file names, not the entire path.

4条回答
  •  天命终不由人
    2020-12-09 09:19

    System.IO.Path is your friend here:

    var filenames = from fullFilename
                    in Directory.EnumerateFiles(targetdirectory,"backup-*.zip")
                    select Path.GetFileName(fullFilename);
    
    foreach (string filename in filenames)
    {
        // ...
    }
    

提交回复
热议问题