开发者

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

开发者 https://www.devze.com 2023-02-25 03:26 出处:网络
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, \"^

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

精彩评论

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