vb.net 如何在 Visual Basic Express 2010 中激活 FileSystemObject?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8485589/
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 activate the FileSystemObject in Visual Basic Express 2010?
提问by user900973
I do have a "Microsoft Scripting Runtime" reference and added the "Scrrun.dll" file in Projects > References. But the code below triggers an error.
我确实有一个“Microsoft Scripting Runtime”参考,并在“项目”>“参考”中添加了“Scrrun.dll”文件。但是下面的代码触发了一个错误。
Error 1 Type 'FileSystemObject' is not defined. C:\Temporary Projects\WindowsApplication1\Form1.vb 6 24 WindowsApplication1
Error 2 Type 'Folder' is not defined. C:\Temporary Projects\WindowsApplication1\Form1.vb 7 20 WindowsApplication1
错误 1 未定义类型“FileSystemObject”。C:\Temporary Projects\WindowsApplication1\Form1.vb 6 24 WindowsApplication1
错误 2 未定义类型“文件夹”。C:\Temporary Projects\WindowsApplication1\Form1.vb 7 20 WindowsApplication1
Dim fso As New FileSystemObject
Dim fld As Folder
回答by Heinzi
If you want to use VB.NET, I suggest that you do it "the .NET way" instead of relying on old COM libraries: Have a look at the System.IO.Directory.GetFiles method.
如果您想使用 VB.NET,我建议您使用“.NET 方式”而不是依赖旧的 COM 库:查看System.IO.Directory.GetFiles 方法。
That being said, let me answer your question: The objects you seek are in the Scripting
namespace, so the following should fix your issue:
话虽如此,让我回答您的问题:您寻找的对象在Scripting
名称空间中,因此以下内容应该可以解决您的问题:
Dim fso As New Scripting.FileSystemObject()
Dim fld As Scripting.Folder
Alternatively, you can just importthe namespace:
或者,您可以只导入命名空间:
Imports Scripting
Module Module1
Sub Main()
Dim fso As New FileSystemObject()
Dim fld As Folder
...
End Sub
End Module