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();
精彩评论