c#Directory.GetFiles应用程序根目录的文件结构
我有以下代码:c#Directory.GetFiles应用程序根目录的文件结构,c#,C#,我有以下代码: string root = Path.GetDirectoryName(Application.ExecutablePath); List<string> FullFileList = Directory.GetFiles(root, "*.*", SearchOption.AllDirectories).Where(name => { return !(name.EndsWith("dmp") ||
string root = Path.GetDirectoryName(Application.ExecutablePath);
List<string> FullFileList = Directory.GetFiles(root, "*.*",
SearchOption.AllDirectories).Where(name =>
{
return !(name.EndsWith("dmp") || name.EndsWith("jpg"));
}).ToList();
string root=Path.GetDirectoryName(Application.ExecutablePath);
List FullFileList=Directory.GetFiles(根“***”,
SearchOption.AllDirectories)。其中(name=>
{
返回!(name.EndsWith(“dmp”)| name.EndsWith(“jpg”);
}).ToList();
现在它工作得很好,但是它的文件名很长。
有没有办法把这条路一直挖到根?但仍然显示所有子文件夹吗
Root=C:\Users\\Desktop\Test\
但是代码将从C返回整个路径:
而我更喜欢的是,如果我能直接取出根的话。但之后仍保留文件结构
乙二醇
C:\Users\\Desktop\Test\hi\hello\files.txt
会回来吗
\hi\hello\files.txt
我知道我可以迭代生成的文件列表并逐个删除,我想知道我是否可以直接过滤掉它。使用LINQ的强大功能:
string root = Path.GetDirectoryName(Application.ExecutablePath);
List<string> FullFileList = Directory.GetFiles(root, "*.*", SearchOption.AllDirectories)
.Where(name =>
{
return !(name.EndsWith("dmp") || name.EndsWith("jpg"));
})
.Select(file => file.Replace(root, "")
.ToList();
string root=Path.GetDirectoryName(Application.ExecutablePath);
List FullFileList=Directory.GetFiles(根“***”,SearchOption.AllDirectories)
。其中(名称=>
{
返回!(name.EndsWith(“dmp”)| name.EndsWith(“jpg”);
})
.Select(文件=>file.Replace(根“”)
.ToList();
ah dangit,浏览了整个列表,忽略了.Select()谢谢!