开发者

How convert type of List<System.IO.FileInfo> to List<string>?

I need to convert this type of List to List of string:

var fileName = (new DirectoryInfo(filePath)).GetFiles(".", SearchOption.AllDirectories开发者_如何学C).Where(a => Regex.IsMatch(a.Name, "^[^*]*" + logSelected + ".jpg$")).ToList();

somebody know how is it?


var fileName = (new DirectoryInfo(filePath))
.GetFiles(".", SearchOption.AllDirectories)
.Where(a => Regex.IsMatch(a.Name, "^[^*]*" + logSelected + ".jpg$"))
.Select(a => a.Name)
.ToList();

Or change a.Name in the Select method for the property you need.


try adding .Select(fi => fi.Name)

List<string> fileNames = (new DirectoryInfo(filePath)).GetFiles(".", SearchOption.AllDirectories)
            .Where(a => Regex.IsMatch(a.Name, "^[^*]*" + logSelected + ".jpg$"))
            .Select(fi => fi.Name)
            .ToList();


            var fileName = (new DirectoryInfo(filePath)).GetFiles(".", SearchOption.AllDirectories)
            .Where(a => Regex.IsMatch(a.Name, "^[^]" + logSelected + ".jpg$"))
            .Select(fi=>fi.FullName)
            .ToList();


var fileName = new DirectoryInfo(filePath)
                   .GetFiles(".", SearchOption.AllDirectories)
                   .Where(a => Regex.IsMatch(a.Name, "^[^*]*" + logSelected + ".jpg$"))
                   .Select(x => x.Name)
                   .ToList();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜