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.
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/