ASP.Net core 1 列出给定目录中的文件 [英] ASP.Net core 1 list files in given directory

查看:21
本文介绍了ASP.Net core 1 列出给定目录中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要列出给定文件夹中存在的所有文件,在 ASP.Net core 1 中使用 C#.类似早期版本中的 System.IO.Directory.GetFiles().>

I need to list all files that are present in a given folder, using C# for ASP.Net core 1. Something like System.IO.Directory.GetFiles() in earlier versions.

推荐答案

你可以这样做:

foreach (string file in Directory.EnumerateFiles(
            pathToFolder, 
            "*" , 
            SearchOption.AllDirectories) 
            )
        {
            // do something

        }

请注意,我也在递归子目录,这可能是您想要的,也可能不是您想要的

note that I'm recursing child directories too which may or may not be what you want

这篇关于ASP.Net core 1 列出给定目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆