Read AND write to a file?

I have a very simple need: to read from a file, then later update the value in it. A single digit value, incremented.

I would greatly prefer NOT to bother the user with having to verify that it is ok to replace the file (which seems to me what happens if I read from a textinputstream, close it, then reopen the file, recreating it if you will, as a textoutputstream, write the new value to it, and close it). (This is the best basic scenario I am able to piece together from the documentation.)

Appending to the file, I think, would get rid of that problem (bothering the user) but would leave the original value as the first line. I could kludge around that, I think, but I’m hoping against hope there is a way to read, delete the value, then append (assuming, of course, that I’m right that in that case I don’t need to bother the user). However, I haven’t found anything to that effect in the documentation.

Is there any hope for me? Or do I need to either kludge when I open it to get the value or bother the user when I update the value?

Thanks so much,
Carolyn B-G

Oh, and one additional question: is this going to work differently on a mac than on a windows computer? I’m currently developing on a mac, but this needs to work on windows as well (just got a laptop at work, so I’ll be able to test that when I’m at work). Thanks, C

TextOutputStream.Create does not prompt for permission from the user when overwriting a file in my tests. What does your code look like?

Hmm… while continuing to work with this stuff after writing the above msg I discovered I was using an older way of opening and closing files (I am updating a program first written in 2006 in RB). In the process of re-writing everything to match the current examples in the documentation, the problem I saw earlier this afternoon went away! That particular bit seems to be working happily now. (I am also trying to sync up my code with that of another person who has done things in yet other ways than I did 6 years ago or than I would do now…leading to more fun and games.)

Thanks for replying, Paul. I think at this point this particular issue has been resolved.

Paul (or anyone else),

Just to verify: if the file is being created from scratch there WILL always be a prompt for permission from the user to create the file (with the opportunity for the user to make changes), right? I have someone from NASA (no less) wanting this prompt to not show up even when I’m creating a new output file. A definitive answer of “no, that’s not possible, just live with it” would, while not making him happy on that point, at least be a definitive answer.

Thanks so much for your time.

Creating a file using TextOutputStream.Create does not prompt. How are you creating this file?

dim outputfilename as string
dim SubjectOutputFolderItem as folderItem
dim SubjectDataTextOutputStream as TextOutputStream

// file creation code, based on example in Language Reference; file in this case does not previously exist
outputfilename = initials.text+“s"+str(session_number) + "” +DateText+ “.txt”
SubjectOutputFolderItem = GetSaveFolderItem(FileTypes1.Text, outputfilename)
SubjectDataTextOutputStream = TextOutputStream.Create(SubjectOutputFolderItem)

// I think I’ve got all the needed pieces here…

This will prompt
SubjectOutputFolderItem = GetSaveFolderItem(FileTypes1.Text, outputfilename)

You can use “getfolderitem” to not prompt

Thank you! That does seem to work!

Now on to the problems of doing these things on a windows machine instead of on a mac…