can `FileWrite` overwrite contents of an existing ...
# cfml-beginners
c
can
FileWrite
overwrite contents of an existing file, or will i need to
FileDelete if FileExists
and then
FileWrite
?
a
Did you try? What happened?
c
i haven’t tried yet, i’m still reading up on everything before getting into the code. just trying to figure out what all i need to do to accomplish the program.
r
Also, cfdocs.org can probably answer this.
a
Fair enough. I recommend you start with the simplest code, which would be to just write the file. Run the code twice. If it overwrites? Cool: no further action to worry about. If it errors... then decide how to deal with it. Don't try to solve problems you don't have yet
c
Good advice, thanks friends.
a
@Rodney I looked at the CF and Lucee docs, and they don't say anything. Nor does cfdocs. But it's always good to start with the docs, yes. And @Cody Kaczynski then you can include in your question "I looked at the docs here [url] and it doesn't say one way or the other". Saves us making suggestions to RTFM if you have RTFMed. And... like... always RTFM first 😉
c
Yeah I should’ve mentioned I did look at Cfdocs but it didn’t answer my question. That’s how I learned about those methods to begin with
a
OK, so write two lines of code that write to the same file twice and see what happens. That's super quick to test
r
Well, there is a fileAppend as well. 😉
c
Will do 🙂
a
(I would have to do this to answer your questions, as will most other ppl, so... you might as well try it and answer it for us!)
r
I agree with Adam though. Test first and if you have a problem then ask and supply test code, the error received, and what you were expecting.
a
NB: I know I'm being a bit of a pain and not just answering the frickin question, but it's better in the long run to get into the habit of doing some investigation first. And as a quid pro quo, I'll stick with ya as other stuff crops up.
c
late to this but if anyone was curious,
FileWrite
doesn’t need the file to exist, and it will also overwrite the existing contents 🙂