Can someone please confirm this behavior?

  • Thread starter Aaron Bertrand - MVP
  • Start date
A

Aaron Bertrand - MVP

Based on a complaint that one of my articles just links to the MS
documentation, I'm writing a tutorial on FileSystemObject. However I'm
currently getting stalled by this bug.

Environment: Windows Server 2003, IIS 6.0, VBScript 5.6, all windows and IE
update patches (to my knowledge).

From
msdn.microsoft.com/library/en-us/script56/html/jsmthcreatetextfile.asp

The FileSystemObject doc for CreateTextFile states for the overwrite
parameter:

"Optional.
Boolean value that indicates whether you can overwrite an existing file. The
value is true if the file can be overwritten, false if it can't be
overwritten. If omitted, existing files are not overwritten. "

I believe "If omitted, existing files are not overwritten" is an inaccurate
statement. The following code definitely overwrites the file.

<%
set fso = CreateObject("Scripting.FileSystemObject")

set fs = fso.createTextFile(Server.MapPath("foo.txt"))
fs.writeline("foo!")
fs.close: set fs = nothing

set fs = fso.createTextFile(Server.MapPath("foo.txt"))
fs.writeline("overwrite!")
fs.close: set fs = nothing

fso.close: set fso = nothing
%>

According to the doc, calling CreateTextFile(filename) should be equivalent
to calling CreateTextFile(filename, false). However when I do the former,
it overwrites the file (try it out, and examine foo.txt). When I do the
latter, I get the following error:

Microsoft VBScript runtime error '800a003a'
File already exists

So, (a) is the documentation incorrect, (b) is FileSystemObject behaving
incorrectly, (c) are the docs I'm looking at outdated, or (d) is there
potentially some configuration issue in my environment that makes this
script misbehave (e.g. does it work right for you)?

I just want to make sure that if the behavior is correct and the docs are
wrong, or if the docs or correct and the behavior is wrong, I convey the
correct location of the bug. :)

Thanks in advance.
 
R

Ray at

Aaron Bertrand - MVP said:
I believe "If omitted, existing files are not overwritten" is an inaccurate
statement. The following code definitely overwrites the file.

Yep, same thing here. With no argument passed, file is overwritten. With
False passed, I get the "file already exists" as expected, and with True, it
behaves as though it was omitted.

So, (a) is the documentation incorrect, (b) is FileSystemObject behaving
incorrectly, (c) are the docs I'm looking at outdated, or (d) is there
potentially some configuration issue in my environment that makes this
script misbehave (e.g. does it work right for you)?

I'll pick a.


I tried this on W2K Server with WSH5.6, btw.

Ray at home
 
C

Chris Hohmann

Aaron Bertrand - MVP said:
Based on a complaint that one of my articles just links to the MS
documentation, I'm writing a tutorial on FileSystemObject. However I'm
currently getting stalled by this bug.

Environment: Windows Server 2003, IIS 6.0, VBScript 5.6, all windows and IE
update patches (to my knowledge).

From
msdn.microsoft.com/library/en-us/script56/html/jsmthcreatetextfile.asp

The FileSystemObject doc for CreateTextFile states for the overwrite
parameter:

"Optional.
Boolean value that indicates whether you can overwrite an existing file. The
value is true if the file can be overwritten, false if it can't be
overwritten. If omitted, existing files are not overwritten. "

I believe "If omitted, existing files are not overwritten" is an inaccurate
statement. The following code definitely overwrites the file.

<%
set fso = CreateObject("Scripting.FileSystemObject")

set fs = fso.createTextFile(Server.MapPath("foo.txt"))
fs.writeline("foo!")
fs.close: set fs = nothing

set fs = fso.createTextFile(Server.MapPath("foo.txt"))
fs.writeline("overwrite!")
fs.close: set fs = nothing

fso.close: set fso = nothing
%>

According to the doc, calling CreateTextFile(filename) should be equivalent
to calling CreateTextFile(filename, false). However when I do the former,
it overwrites the file (try it out, and examine foo.txt). When I do the
latter, I get the following error:

Microsoft VBScript runtime error '800a003a'
File already exists

So, (a) is the documentation incorrect, (b) is FileSystemObject behaving
incorrectly, (c) are the docs I'm looking at outdated, or (d) is there
potentially some configuration issue in my environment that makes this
script misbehave (e.g. does it work right for you)?

I just want to make sure that if the behavior is correct and the docs are
wrong, or if the docs or correct and the behavior is wrong, I convey the
correct location of the bug. :)

Thanks in advance.

Same here.

Notes:
1. Here's someone else who encountered the same thing. He didn't get an
answer either.
http://groups.google.com/[email protected]

2. I declared but did not initialize a variable "a" and passed that as
the overwrite parameter and it behaved as advertised in the
documentation (i.e.. File exists error was thrown). Perhaps the
CreateTextFile method is dealing with the absence of the argument in a
non-standard way. Pure conjecture on my part.

-Chris Hohmann
 
S

Sylvain Lafontaine

A quick look at the Microsoft Scripting Runtime (scrrun.dll) with the Object
Browser show that the second parameter is True by default:
Function CreateTextFile(ByVal FileName As String, [ByVal Overwrite As
Boolean = True], [ByVal Unicode As Boolean = False]) As ITextStream

Member of Scripting.FileSystemObject

Create a file as a TextStream

From this, we can say that the documentation is clearly wrong. This is on
XP with VBScript 5.6.

S. L.
 
M

Mark Schupp

"Those who live by the optional parameter, die by the optional parameter"
(slightly paraphrased).

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com


Sylvain Lafontaine said:
A quick look at the Microsoft Scripting Runtime (scrrun.dll) with the Object
Browser show that the second parameter is True by default:
Function CreateTextFile(ByVal FileName As String, [ByVal Overwrite As
Boolean = True], [ByVal Unicode As Boolean = False]) As ITextStream

Member of Scripting.FileSystemObject

Create a file as a TextStream

From this, we can say that the documentation is clearly wrong. This is on
XP with VBScript 5.6.

S. L.


Aaron Bertrand - MVP said:
Based on a complaint that one of my articles just links to the MS
documentation, I'm writing a tutorial on FileSystemObject. However I'm
currently getting stalled by this bug.

Environment: Windows Server 2003, IIS 6.0, VBScript 5.6, all windows and IE
update patches (to my knowledge).

From
msdn.microsoft.com/library/en-us/script56/html/jsmthcreatetextfile.asp

The FileSystemObject doc for CreateTextFile states for the overwrite
parameter:

"Optional.
Boolean value that indicates whether you can overwrite an existing file. The
value is true if the file can be overwritten, false if it can't be
overwritten. If omitted, existing files are not overwritten. "

I believe "If omitted, existing files are not overwritten" is an inaccurate
statement. The following code definitely overwrites the file.

<%
set fso = CreateObject("Scripting.FileSystemObject")

set fs = fso.createTextFile(Server.MapPath("foo.txt"))
fs.writeline("foo!")
fs.close: set fs = nothing

set fs = fso.createTextFile(Server.MapPath("foo.txt"))
fs.writeline("overwrite!")
fs.close: set fs = nothing

fso.close: set fso = nothing
%>

According to the doc, calling CreateTextFile(filename) should be equivalent
to calling CreateTextFile(filename, false). However when I do the former,
it overwrites the file (try it out, and examine foo.txt). When I do the
latter, I get the following error:

Microsoft VBScript runtime error '800a003a'
File already exists

So, (a) is the documentation incorrect, (b) is FileSystemObject behaving
incorrectly, (c) are the docs I'm looking at outdated, or (d) is there
potentially some configuration issue in my environment that makes this
script misbehave (e.g. does it work right for you)?

I just want to make sure that if the behavior is correct and the docs are
wrong, or if the docs or correct and the behavior is wrong, I convey the
correct location of the bug. :)

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top