插入路径并从文件中读取 [英] inserting a path and reading from files

查看:63
本文介绍了插入路径并从文件中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个用户输入起始路径的程序,然后搜索用户提供的路径下的所有hrd驱动器和目录.
如何实现呢?
我必须使用递归吗?请帮助我

I want to make a program where a user input starting path, then search all hrd drive and directories under the path provided by the user.
How to achieve this ?
do i have to use recursion? please help me

推荐答案

您要使用的是DirectoryInfo对象和GetFiles方法.

What you want to use is the DirectoryInfo object and the GetFiles method.

string userInputPath = string.Empty;
string fileType = string.Empty;

//Set parameters to what you need

System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(userInputPath);
var files = dInfo.GetFiles(fileType, System.IO.SearchOption.AllDirectories);



这是 MSDN [



Here is the reference on MSDN[^]. It is pretty straight forward.


您可以使用
DirectoryInfo[] GetDirectories(
    string searchPattern,
    SearchOption searchOption
)



阅读
[ [^ ].



read this[^] and this[^].


这篇关于插入路径并从文件中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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