插入路径并从文件中读取 [英] inserting a path and reading from files
本文介绍了插入路径并从文件中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想制作一个用户输入起始路径的程序,然后搜索用户提供的路径下的所有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 theDirectoryInfo
object and theGetFiles
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屋!
查看全文