vb.net 获取目录中的文件名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16670750/
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-09 16:54:58 来源:igfitidea点击:
vb.net get file names in directory?
提问by ABANDOND ACOUNT
I have the following code.
我有以下代码。
Dim text As String = IO.File.ReadAllText("C:\Example.xtp")
This code is specific to a single file, however I would like to file.readalltext
for every file in a particular directory.
此代码特定于单个文件,但是我想file.readalltext
针对特定目录中的每个文件。
How can I achieve this?
我怎样才能做到这一点?
回答by the_lotus
You will need to use the IO.Directory.GetFilesfunction.
您将需要使用IO.Directory.GetFiles函数。
Dim files() As String = IO.Directory.GetFiles("c:\")
For Each file As String In files
' Do work, example
Dim text As String = IO.File.ReadAllText(file)
Next
回答by user2933082
Dim fileEntries As String() = Directory.GetFiles("YourPath", "*.txt")
' Process the list of .txt files found in the directory. '
Dim fileName As String
For Each fileName In fileEntries
If (System.IO.File.Exists(fileName)) Then
'Read File and Print Result if its true
ReadFile(fileName)
End If
TransfereFile(fileName, 1)
Next
回答by Edper
System.IO.Directory.GetFiles()
could help
有帮助
回答by SysDragon
Try this:
尝试这个:
Dim text As String = ""
Dim files() As String = IO.Directory.GetFiles(sFolder)
For Each sFile As String In files
text &= IO.File.ReadAllText(sFile)
Next