Hello,

I have a vbscript which creates a text file, add some lines of text,
and then tries to save it. The problem is that when I try to save the
file, I get an error stating "bad file name or number" with the
following line of code:

Set objFile = objFSO.CreateTextFile(strPath, True)
objFile.Write(strList)
objFile.Close

strPath is equal to "C:\Program Files\Some App\FILE" where FILE is the
name. The application that I am updating this file for expects it to
be named FILE with no extension. I can only assume that the error is
coming from the fact that vbscript thinks FILE is a directory name. Is
there anyway to do this with a text file with no extension? Thanks for
any help you can offer.

JG

Re: Error saving text file with no extension by McKirahan

McKirahan
Tue Jul 08 08:43:47 CDT 2008

"Jim Gregg" <crazytek@gmail.com> wrote in message
news:4b0d9f38-250a-4685-9d92-9537623d2c41@c65g2000hsa.googlegroups.com...
> Hello,
>
> I have a vbscript which creates a text file, add some lines of text,
> and then tries to save it. The problem is that when I try to save the
> file, I get an error stating "bad file name or number" with the
> following line of code:
>
> Set objFile = objFSO.CreateTextFile(strPath, True)
> objFile.Write(strList)
> objFile.Close
>
> strPath is equal to "C:\Program Files\Some App\FILE" where FILE is the
> name. The application that I am updating this file for expects it to
> be named FILE with no extension. I can only assume that the error is
> coming from the fact that vbscript thinks FILE is a directory name. Is
> there anyway to do this with a text file with no extension? Thanks for
> any help you can offer.

The following works for me:

Option Explicit
Const cFIL = "C:\Temp\FILE"
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objCTF
Set objCTF = objFSO.CreateTextFile(cFIL, True)
objCTF.Write("Hello World")
Set objCTF = Nothing
Set objFSO = Nothing

Perhaps, your path "C:\Program Files\Some App\" does not exist.

What's your O/S?



Re: Error saving text file with no extension by Richard

Richard
Tue Jul 08 08:43:30 CDT 2008

Jim Gregg wrote:

> I have a vbscript which creates a text file, add some lines of text,
> and then tries to save it. The problem is that when I try to save the
> file, I get an error stating "bad file name or number" with the
> following line of code:
>
> Set objFile = objFSO.CreateTextFile(strPath, True)
> objFile.Write(strList)
> objFile.Close
>
> strPath is equal to "C:\Program Files\Some App\FILE" where FILE is the
> name. The application that I am updating this file for expects it to
> be named FILE with no extension. I can only assume that the error is
> coming from the fact that vbscript thinks FILE is a directory name. Is
> there anyway to do this with a text file with no extension? Thanks for
> any help you can offer.

I'm not able to duplicate the problem. I can create a file with no extension
(called FILE) with similar code.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--



Re: Error saving text file with no extension by ekkehard

ekkehard
Tue Jul 08 08:53:12 CDT 2008

Jim Gregg schrieb:
> Hello,
>
> I have a vbscript which creates a text file, add some lines of text,
> and then tries to save it. The problem is that when I try to save the
> file, I get an error stating "bad file name or number" with the
> following line of code:
>
> Set objFile = objFSO.CreateTextFile(strPath, True)
> objFile.Write(strList)
> objFile.Close
>
> strPath is equal to "C:\Program Files\Some App\FILE" where FILE is the
> name. The application that I am updating this file for expects it to
> be named FILE with no extension. I can only assume that the error is
> coming from the fact that vbscript thinks FILE is a directory name. Is
> there anyway to do this with a text file with no extension? Thanks for
> any help you can offer.
>
> JG

If there is a directory "C:\Program Files\Some App\FILE", an attempt
to .CreateTextFile( "C:\Program Files\Some App\FILE", True ) will fail
with a "permission denied" error.

Re: Error saving text file with no extension by mayayana

mayayana
Tue Jul 08 09:22:07 CDT 2008


>
> If there is a directory "C:\Program Files\Some App\FILE", an attempt
> to .CreateTextFile( "C:\Program Files\Some App\FILE", True ) will fail
> with a "permission denied" error.

That's a different issue and would typically only
apply to Vista.



Re: Error saving text file with no extension by ekkehard

ekkehard
Tue Jul 08 10:19:09 CDT 2008

mayayana schrieb:
>> If there is a directory "C:\Program Files\Some App\FILE", an attempt
>> to .CreateTextFile( "C:\Program Files\Some App\FILE", True ) will fail
>> with a "permission denied" error.
>
> That's a different issue and would typically only
> apply to Vista.
>
>

I used code like this:

On Error Resume Next
WScript.Echo 0, CreateObject( "WScript.Shell" ) _
.RegRead( "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProductName" )
If 0 <> Err.Number Then
WScript.Echo 1, CreateObject( "WScript.Shell" ) _
.RegRead( "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion" )
End If
On Error GoTo 0

Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sName
For Each sName In Array( "noextension", "same.as" )

If oFS.FolderExists( sName ) Then oFS.DeleteFolder sName
If oFS.FileExists( sName ) Then oFS.DeleteFile sName

oFS.CreateTextFile( sName, True ).Write "Was wollt Ihre denn, es geht doch!"
WScript.Echo 2, oFS.OpenTextFile( sName ).ReadAll

oFS.DeleteFile sName
oFS.CreateFolder sName

On Error Resume Next
oFS.CreateTextFile( sName, True ).Write "Was wollt Ihre denn, es geht doch!"
WScript.Echo 3, Err.Number, Err.Description
On Error GoTo 0

Next

to verify that creating a text file with the same name as an existing
directory fails under W2K and XP.

Re: Error saving text file with no extension by OldPedant

OldPedant
Tue Jul 08 20:11:00 CDT 2008

"mayayana" wrote:
>
> >
> > If there is a directory "C:\Program Files\Some App\FILE", an attempt
> > to .CreateTextFile( "C:\Program Files\Some App\FILE", True ) will fail
> > with a "permission denied" error.
>
> That's a different issue and would typically only
> apply to Vista.

Pardon me, but that's nonsense. It applies to virtually any operating
system ever created that supports directories, at all.

You can't create a file within a given directory that has the same name as a
subdirectory of that same given directory.

Was true in MS-DOS version 1 and in various operating systems before that.
Is true in Linux, Unix, and who knows what other operating systems.



Re: Error saving text file with no extension by mayayana

mayayana
Tue Jul 08 22:10:12 CDT 2008

> > That's a different issue and would typically only
> > apply to Vista.

>
> Pardon me, but that's nonsense.

Yes. I misread the post, thinking that he was
referring to permission issues in Program Files.