"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:%23pgwR1SxDHA.1060@TK2MSFTNGP12.phx.gbl...[color=blue]
> A quick look at the Microsoft Scripting Runtime (scrrun.dll) with the[/color]
Object[color=blue]
> 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" <aaron@TRASHaspfaq.com> wrote in message
> news:e%23aCBlQxDHA.1596@TK2MSFTNGP10.phx.gbl...[color=green]
> > 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[/color]
> IE[color=green]
> > 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.[/color]
> The[color=green]
> > 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[/color]
> inaccurate[color=green]
> > 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[/color]
> equivalent[color=green]
> > to calling CreateTextFile(filename, false). However when I do the[/color][/color]
former,[color=blue][color=green]
> > 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[/color][/color]
are[color=blue][color=green]
> > 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/
> >
> >[/color]
>
>[/color]