Solved Is there an important difference between scripting.filesystemobject and wscript.filesystemobject?

JMongi

Active member
Local time
Today, 14:16
Joined
Jan 6, 2021
Messages
802
Microsoft help docs use scripting.fileystemobject. I also have some code samples that use that. But, I also have some codesamples that use wscript. I've seen posts on here using both.

I know that wscript is a windows module that translates vbscript. Is there any appreciable difference between a line of Access VBA that says:
Set f = CreateObject("Scripting.FileSystemObject")
vs
Set f = CreateObject("wscript.FileSystemObject")

I'm trying to standardize accross modules and code. Thanks!

Edit: See post #11 for the answer!
 
Last edited:
I was just quoting a single disconnected line of code. Just in case it's confusing, here is the full potential property taken from this page.

Code:
Public Property Get FSO() As Object
Static f As Object
If f Is Nothing Then
    Set f = CreateObject("Wscript.FileSystemObject")
Else
    'return existing f
End If
Set FSO = f
End Property

I've seen reference in recent post to both Wscript.FileSystemObject and Scripting.FileSystemObject and wonder if there is a difference, pro/con or whatever.
 
Yes, but did you try that block of code?

My thoughts are that it is a typo in the example.

Have a go.
 
To test, paste the following in a standard module:
Code:
Public Property Get FSO() As Object
  Static f As Object
  If f Is Nothing Then
    Set f = CreateObject("WScript.FileSystemObject")
  End If
  Set FSO = f
End Property

Function FSOFileExists(FileToTest As String) As Boolean

  FSOFileExists = FSO.FileExists(FileToTest)
 
End Function

Then in the Immediate Window (Ctrl+G) type:
Code:
?FSOFileExists(CurrentProject.Path & "\" & CurrentProject.Name)
and hit Enter

My guess is that you will get a run-time error 429: ActiveX component can't create object.
 
You are correct in that it didn't work. But I don't know the typo. Changing it to Scripting.FileSystemObject works fine. So what is the typo/problem?
 
That's not really the definition of a typo is it? A typo is me spelling cat "CATT". A typo is not me spelling dog "CAT".

This was a very long way around of saying that there I had the wrong idea. Which is what I was going for in the first place. So, I'll take a stab at answering my own question...

One can create an object with either CreateObject("Wscript. or CreateObject("Scripting.

One CANNOT create a file system object with either statement. That can only be done with CreateObject("Scripting.FileSystemObject")
 
Either statement??
The latter is correct?
 
That's what it appears I'm being told. Am I wrong? I had to answer my own question ;)

If I search for "Wscript.FileSystemObject" on this forum, the only hits I get are this thread.
If I search for "Scripting.FileSystemObject", I get a whole lot of hits.
 
Semantics aside, if you want a FileSystemObject you must use CreateObject("Scripting.FileSystemObject")
 
I admit to being mildly irritated at one point in this process, but, the coffee is kicking in now. My apologies. :coffee::D Thanks for your help.
 
FYI, I've just sent an email to the author of the article, Ben Clothier, to alert him of the error
 
Good thing CB isn't the sensitive type...
:ROFLMAO:
the coffee is kicking in now.
Never attempt anything before coffee!!!

The reason I wanted to get you to try it is twofold:

1. Although I had never before come across wscript.FileSystemObject, Ben Clothier really knows his Access well (you should pay attention when you come across his stuff) and perhaps it might work for you even though it didn't work for me. I only have old Access 2007 - maybe something might have changed that I'm not aware of.

2. You will learn much better by trying something out and seeing the result rather than just believing any answer I give you. Why should you trust my answer any more than Ben's? Having done it yourself, you can come to your own conclusion!

All that said, wscript and 'Scripting' are two different object models but visually are easily confused, and I have probably seen before cases where they have been mixed up.

Enjoy your coffee! :coffee:
 
Ben replied almost immediately.
Apparently the command is also in the WScript library but Ben also got an error when he tested it.
Probably error 429 as I did when I tried it and as you suggested would happen.
Anyway, I've suggested he modifies it
 
I looked at a few resources describing the WSH object model (eg this one and similar) and found no reference to a FileSystemObject, but I was prepared to learn something new.
 

Users who are viewing this thread

Back
Top Bottom