我需要将这种类型的List转换为字符串列表:
var fileName = (new DirectoryInfo(filePath)).GetFiles(".", SearchOption.AllDirectories).Where(a => Regex.IsMatch(a.Name, "^[^*]*" + logSelected + ".jpg$")).ToList();
有人知道怎么回事?
答案 0 :(得分:4)
var fileName = (new DirectoryInfo(filePath))
.GetFiles(".", SearchOption.AllDirectories)
.Where(a => Regex.IsMatch(a.Name, "^[^*]*" + logSelected + ".jpg$"))
.Select(a => a.Name)
.ToList();
或者在Select方法中更改所需属性的a.Name
。
答案 1 :(得分:0)
尝试添加.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();
答案 2 :(得分:0)
var fileName = new DirectoryInfo(filePath)
.GetFiles(".", SearchOption.AllDirectories)
.Where(a => Regex.IsMatch(a.Name, "^[^*]*" + logSelected + ".jpg$"))
.Select(x => x.Name)
.ToList();
答案 3 :(得分:0)
var fileName = (new DirectoryInfo(filePath)).GetFiles(".", SearchOption.AllDirectories)
.Where(a => Regex.IsMatch(a.Name, "^[^]" + logSelected + ".jpg$"))
.Select(fi=>fi.FullName)
.ToList();