Author Topic: FileObject Help  (Read 2702 times)

Ok, so I'm making an add-on that deals with using a .txt file. So far I've made it
so that it can write into it (in my case it writes the client's BLID) so that the .txt
shows a list of people that have permission. Now I just need to be able to take
their permission away... how do I do that without erasing everything inside the
.txt file?

Well first you read everything inside the txt file, you edit the text to whatever you want it to be, then use .openForWrite to overwrite everything in the file with the edited text.

Well first you read everything inside the txt file, you edit the text to whatever you want it to be, then use .openForWrite to overwrite everything in the file with the edited text.
Say there's like 3 lines... how would I be able to just erase or edit the middle line?

Say there's like 3 lines... how would I be able to just erase or edit the middle line?
Well, when you're reading in the file using .readLine(), check if it's the 2nd line, and if so, skip it.

For your purposes, do you already have a list of the relevant BL_IDs somewhere else, such as a global variable or an object? If so, you can just use openForWrite to re-record the list after modification and not have to worry about reading and editing the data straight from the file.

If I get what your saying, I don't think it would work because it's supposed to be working
with multiple people. Otherwise I'm having a little trouble comprehending lol... Maybe
giving examples would help.

Instead of saving it as a text file why don't you make it a server pref? Like how admin/SA are stored instead? It'd be quite a bit easier.

I guess I could... I would still like to know the other method

Well then you do like they were saying. You use the read method to read and store all of the lines in the text document into a variable. Then you pull out the string you don't want, and then write the variable back into the file. So if you had a file with:
19273
2199
10382
And you wanted to remove 2199, you'd read all three lines and have them stored in your variable, so you'd end up with your variable being equal to "19273" NL "2199" NL "10382" then you just use something like strReplace on it to remove the line.