Re: read-modify-write textfile problem
- From: GerryM <GerryM@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 6 Aug 2005 17:37:23 -0700
You are exactly right; I should have been more explicit. I had exactly what
you showed, namely
fileA = "C:\somefolder\myfileA.txt"
fileB = "C:\somefolder\myfileB.txt" ' <<<<< 1 >>>>>
'''' and further:
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set fA = fso.OpenTextFile(fileA, ForReading)
If Not fA.AtEndOfStream Then
TxtArray = Split(fA.ReadAll, vbCrLf)
End If
fA.Close
''' ... now modify TxtArray and write it to fileB:
Set fB = fso.CreateTextFile(fileB, True) ' <<<<< 2 >>>>>
For i = 0 To UBound(TxtArray)
fB.WriteLine TxtArray(i)
Next
fB.Close
This works fine; fileB indeed contains the modified information.
Now if I replace the statement marked <<<<< 1 >>>>> with
fileB = fileA
the program hangs at statement <<<<< 2 >>>>> with Error 0x888A0046,
Permission Denied.
Sorry about being too brief.
Thanks
Gerry Metze
"Steve Easton" wrote:
> Ok.
> I don't understand "when fileA and fileB are the same"
>
> However one thing I did notice, if "fileA" is a String variable that
> is a path to a file like this:
>
> Dim fileA As String
>
> fileA = "C:\somefolder\myfile.txt"
>
> Then you don't need the quotes "" in the function.
> It should be:
> OpenTextFile(fileA, ForWriting, True)
>
>
> Unless, fileA lives in the same directory as the application, then you could use
> OpenTextFile("fileA.txt", ForWriting, True)
>
> with the quotes.
>
> --
> Steve Easton
> Microsoft MVP FrontPage
> 95isalive
> This site is best viewed............
> ........................with a computer
>
> "GerryM" <GerryM@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:4D644668-84AD-43FF-BE48-8EC01258E8C8@xxxxxxxxxxxxxxxx
> > I can read fileA with OpenTextFile etc. and Close it.
> > I can then modify the textstream and write it to fileB using either
> > OpenTextFile("fileB", ForWriting, True) or CreateTextFile("fileB", True).
> > However, when fileA and fileB are the same I get Error 0x800A0046,
> > Permission Denied. This does not seem to be a "Permission" problem since I
> > can read and write as long as the files are different, but what is it and how
> > do I get around it?
> >
> > Thanks in advance.
> >
> > Gerry Metze
>
>
>
.
- Follow-Ups:
- Re: read-modify-write textfile problem
- From: Steve Easton
- Re: read-modify-write textfile problem
- References:
- read-modify-write textfile problem
- From: GerryM
- Re: read-modify-write textfile problem
- From: Steve Easton
- read-modify-write textfile problem
- Prev by Date: Re: read-modify-write textfile problem
- Next by Date: Setting up discussion web as sub-site w/in larger web site
- Previous by thread: Re: read-modify-write textfile problem
- Next by thread: Re: read-modify-write textfile problem
- Index(es):
Relevant Pages
|