file read/write permissions 
Author Message
 file read/write permissions

i'm wondering if anybody might have some suggestions for me.

i need to read a text file line by line into an array
make some changes to the array
then write back out the file
i can do all this and it works quite nice
here's the glitch
the text file in question is being read and written to by other apps at
varying intervals
when i open it for read with "textIn=f.openAsTextFile"
its possible that another app is actually in the middle of changing it when
i read it
so i don't get all the text i need
i tried creating a loop where i try to do textout=f.appendToTextFile that
counts the number of tries
and keeps trying until textout<>nil or i've reached the max of my counter
but i think there is a bug with this method because even though it keeps
returning nil until the max of the counter
the app ends up running out of memory and crashs
but if i change from appendToTextFile to createTextFile it doesn't run out
of memory in the same loop

the code looks something like this
where f is a file that i have open with write permission the whole time for
worst case scenario

the following runs out of memory

x=0
do
textout=f.appendToTextFile
x=x+1
until textout<>nil or x=30000
if x=30000 then
msgbox "Timed out!"
else
here's where i do the reading if i know its locked
end if

the following doesn't crash but clears out my file before i can read it so
its not a solution

x=0
do
textout=f.createTextFile
x=x+1
until textout<>nil or x=30000
if x=30000 then
msgbox "Timed out!"
else
here's where i do the reading if i know its locked
end if

is their some kind of memory leak with the first method is there something
majorly different about the to ways to open the file
besides that one appends and one starts at the beginning

in summary
i need a way to read from a file that i'm sure nobody has control over but
me
thanks in advance
jeff



Sun, 20 Jul 2003 04:24:35 GMT  
 file read/write permissions
I do something similar to this at my work. We have several program written
by other people that make use of a file, and I need to edit it (at the same
time).

You should always be able to read the file, so I read the file in a buffer,
and save the modifications to another file (ie original file=MyText.doc,
newfile=MyText2.doc). Then I wait in a loop, watching the "read-only" bit to
see if it is open by another app. When it isn't I just quickly delete the
old file by renaming the new one. I do this on Win32, though, not MacOS, so
I don't know what the complications (if any) would be to do this on MacOS.

NOTE: The main "problem" with this idea is that you can possibly lose the
changes made by 1 program while you read the file into the buffer. My
programs can deal with this because the others just use the data, not modify
it.

Hope this helps.
Jeff



Sun, 20 Jul 2003 05:31:06 GMT  
 file read/write permissions
I am still learning RealBasic - but I have used this technique in other
languages and platforms successfully:

What about using another "lock" indicator file to show if another
application is using your data array file? I realise this would mean
changing the other apps that use the file, so might not be possible.

A text file named, for eg: "lock",  could contain 0 to indicate the
data file is available. So your program would change this to 1, and
then process the data array file, when complete change back to 0.

Any other program trying to use the data file would first check the
lock file, and if it contains 1, loop until it is 0.

Of course it is possible 2 programs could read the lock file at the
same instant, and both write 1 back - but this is very unlikely, unless
you have a really large number of applications trying to access the
file simultaneously, in which case it sounds like you need some sort of
multi-user database.

Just an idea.. I hope it may be useful,

Dave



Quote:
> I do something similar to this at my work. We have several program
written
> by other people that make use of a file, and I need to edit it (at
the same
> time).

> You should always be able to read the file, so I read the file in a
buffer,
> and save the modifications to another file (ie original
file=MyText.doc,
> newfile=MyText2.doc). Then I wait in a loop, watching the "read-only"
bit to
> see if it is open by another app. When it isn't I just quickly delete
the
> old file by renaming the new one. I do this on Win32, though, not
MacOS, so
> I don't know what the complications (if any) would be to do this on
MacOS.

> NOTE: The main "problem" with this idea is that you can possibly lose
the
> changes made by 1 program while you read the file into the buffer. My
> programs can deal with this because the others just use the data, not
modify
> it.

> Hope this helps.
> Jeff

Sent via Deja.com
http://www.deja.com/


Sun, 20 Jul 2003 17:56:23 GMT  
 file read/write permissions

Quote:

>I am still learning RealBasic - but I have used this technique in other
>languages and platforms successfully:

>What about using another "lock" indicator file to show if another
>application is using your data array file? I realise this would mean
>changing the other apps that use the file, so might not be possible.

That was actually my first instinct -- much the same way MS Access does the
same thing. However, I don't have access to the other programs' code source
:(

Thanks for the good idea, though! :)

Hope you get your problem worked out alright.
Jeff



Sun, 20 Jul 2003 23:20:22 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Permission to write files to /var/www/html

2. file manipulation and write permission

3. file read permission

4. Clarification: read/write slow, and TCPSocket and sys{read,write}

5. read/write slow, and TCPSocket and sys{read,write}

6. Reading from input file writing to output file

7. Q: simple example of read file->convert char(s)->write file needed

8. Reading a binary file / writing binary data to a file

9. Mystical file permissions on files created by tcl/tk rel 7.6/4.2

10. Newbie questions: write permission, interpreter minimizing

11. How to install on NT without write permissions to c:\winnt

12. binary file read/write acces

 

 
Powered by phpBB® Forum Software