Hobbyist Posted March 7, 2015 Share Posted March 7, 2015 I have a question about FileWrite out of the Help section. Its says: FileWrite ( "filehandle/filename", "text/data" ) and says If a filename is given rather than a file handle, the file will be opened and closed during the function call. And under FileOpen ( "filename" [, mode = 0] ) So if I am using "filehandle", I don't have to FileOpen? And in that case how do I indicate append or over write? If I read this correctly I only need to do that when using "filename". Thanks for any guidance. Hobbyist Link to comment Share on other sites More sharing options...
water Posted March 7, 2015 Share Posted March 7, 2015 FileOpen returns a handle to the file. The file later needs to be closed using FileClose. You can use FileWrite by providing either this handle or the filename. If the filename is used then FileOpen/FileClose is being done implicitely by FileWrite and hence can be omitted. If you need to write to a file more than once then use FileOpen/FileWrite/FileClose for performance reasons. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Hobbyist Posted March 7, 2015 Author Share Posted March 7, 2015 @ water Thanks for the quick response. That makes me think of another question (as I am thinking this through before I start lopping in code). Going with your line of direction, I should really do a FileOpen(and in my case assign a file over write mode) outside any loop of writing? FileOpen(file, mode) for $i = x to y do some stuff FileWrite(file, data @CRLF) next Fileclose. What I gather is, in using the mode of overwrite, the existing data in the file is deleted on the first pass? And therefore I only need delete it once, thus my FileOpen outside the loop. Otherwise i would be deleting my previously written record except for the last one "y" if Open was inside the loop. Thanks again. Link to comment Share on other sites More sharing options...
water Posted March 7, 2015 Share Posted March 7, 2015 Correct. FileOpen and FileClose should be outside the loop. When you set mode to $FO_OVERWRITE then the file is deleted and all new records are appended. Your example should work just fine. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now