469,927 Members | 1,866 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Can someone please confirm this behavior?

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/
Jul 19 '05 #1
7 3780
(BTW - Same behavior on XP Pro.)
Jul 19 '05 #2

"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message
news:e#**************@TK2MSFTNGP10.phx.gbl...

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
Jul 19 '05 #3

"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message
news:e#**************@TK2MSFTNGP10.phx.gbl...
<%
fso.close: set fso = nothing
%>


p.s. fso.close? :P

Ray at home
Jul 19 '05 #4
"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message
news:e%****************@TK2MSFTNGP10.phx.gbl...
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/


Same here.

Notes:
1. Here's someone else who encountered the same thing. He didn't get an
answer either.
http://groups.google.com/groups?thre...3B%40hydro.com

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

Jul 19 '05 #5
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" <aa***@TRASHaspfaq.com> wrote in message
news:e%****************@TK2MSFTNGP10.phx.gbl...
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/

Jul 19 '05 #6
Sory, bad cut & paste, I guess. :-\

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


p.s. fso.close? :P

Ray at home

Jul 19 '05 #7
"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" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...
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" <aa***@TRASHaspfaq.com> wrote in message
news:e%****************@TK2MSFTNGP10.phx.gbl...
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/


Jul 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

87 posts views Thread by expertware | last post: by
7 posts views Thread by Tigger | last post: by
2 posts views Thread by Ike | last post: by
5 posts views Thread by GiJeet | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.