vba 如何列出给定文件夹的所有文件(通过子文件夹递归)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2713838/
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
How to list all files of a given folder (recursively through sub-folder)?
提问by Nam G VU
I'm writing a microsoft word macro and having difficulty with vb.net. Please help.
我正在编写一个 microsoft word 宏并且在使用 vb.net 时遇到了困难。请帮忙。
采纳答案by MarkJ
回答by Hans Olsson
A Word Macro is usually written in VBA rather than VB.Net, I'm assuming that you meant VBA?
Word 宏通常是用 VBA 而不是 VB.Net 编写的,我假设您的意思是 VBA?
Use the FileSystemObject
to access the filesystem and then use recursion to "walk" down. Here's a sample:
使用FileSystemObject
访问文件系统,然后使用递归“走”下来。这是一个示例:
If it's actually VB.Net you're using, the idea will be the same but use System.IO.Directory
rather than the FileSystemObject
.
如果它实际上是您正在使用的 VB.Net,想法将是相同的,但使用System.IO.Directory
而不是FileSystemObject
.