Type 'Scripting.FileSystemObject' is not defined

codefish06 picture codefish06 · Oct 22, 2014 · Viewed 10k times · Source

I have migrated a VB project from 2008 to 2012. As expected, there are many code modification to meet the migration process. As stated in the title, how can I resolved this error?

Here is the line having the said error:

Dim FSO As Scripting.FileSystemObject
FSO = New Scripting.FileSystemObject

Answer

Matt Wilko picture Matt Wilko · Oct 22, 2014

To fix your error you need to add a reference to the FileSystemObject:

Project>Properties>References>Add>COM>Microsoft Scripting Runtime

But there is absolutely no need to use the FileSystemObject to use the file system.

You can use the fully managed methods in the File class in the System.IO namespace: http://msdn.microsoft.com/en-us/library/system.io.file_methods(v=vs.110).aspx