vb.net 将目录的内容存储在数组中,visual basic?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13992433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:38:52  来源:igfitidea点击:

Store contents of a directory in an array, visual basic?

vb.netvisual-studio-2010

提问by Kyle Rohlfing

I am relatively new to visual basic and I am working on a project in which I am going to need to create a "link" to individual files that are within a certain directory. This way the user can see all of the files listed out can click on an individual file and run certain things on it. I am sure there are plenty of ways to do this, but if you guys could please give me a few ideas on how I may accomplish this it would be greatly appreciated.

我对visual basic比较陌生,我正在做一个项目,在这个项目中我需要创建一个“链接”到某个目录中的各个文件。通过这种方式,用户可以看到列出的所有文件,可以单击单个文件并在其上运行某些操作。我相信有很多方法可以做到这一点,但如果你们能给我一些关于我如何实现这一点的想法,我们将不胜感激。

Thanks, Kyle R.

谢谢,凯尔 R。

回答by JMK

Visual Studio uses VB.Net, and you literally do this:

Visual Studio 使用 VB.Net,而您实际上是这样做的:

Dim eachFileInMydirectory As String() = Directory.GetFiles("C:\mydirectory")

Now all of the files in mydirectory are stored in eachFileInMydirectory, which is an array of string. You will need to add the following line to the very top of your VB file:

现在mydirectory 中的所有文件都存储在eachFileInMydirectory 中,它是一个字符串数组。您需要将以下行添加到 VB 文件的最顶部:

Imports System.IO