file.writeTextFile
| Syntax |
file.writeTextFile (f, s, mimeType = nil, blockSize = nil, characterSet = nil, lineEnding = nil, creationDate = nil, type = nil, creator = nil)
|
| Params |
f is the path to the file that you want to create. s is the string to be written as the contents of the file. mimeType is an optional parameter specifying the file's mime-type. If no value is supplied, then the mime-type is looked up in the table at user.webserver.prefs.ext2MIME, based on the file's extension. If no mime-type is found in the table, text/plain is assumed. characterSet is an optional parameter specifying the character set to use. Acceptible values are "mac", "windows", "utf-8", and "utf-16". If no value is specified, the default character set for the platform Frontier is running on will be used. lineEnding is an optional parameter specifying the line-endings to use. Acceptible values are "mac", "windows", and "unix". If no value is specified, the default line-ending for the platform Frontier is running on will be used. creationDate is an optional parameter specifying the file's creation date. If no value is supplied, the current system date/time is used. If the file already exists on disk, the creation date of the existing file is used for the value of creationDate. blockSize is an optional parameter specifying what size blocks to write between yielding processor cycles. If no value is supplied, the entire file is written at once. type is a string4, the MacOS file type code. If not specified, the value is determined by looking it up in the user.webserver.prefs.type2MIME, based on the mimeType. If no type is found, the default is 'TEXT'. creator is a string4, the MacOS creator code. If not supplied, its value is determined by looking it up in the user.webserver.prefs.MIME2creator, based on the mimeType. If no creator is found, a default is generated: For text files, 'ttxt' on MacOS Classic, or ' ' on MacOS X. For HTML files, the value of user.html.prefs.textFileCreator is used.
|
| Action |
Creates a new text file with the specified path, writes the contents to it with the correct line-endings and character set as specified by the input parameters, and closes the file.
|
| Returns |
true
|
| Examples |
file.writeTextFile ("C:\\Program Files\\Frontier\\smallTextFile.txt", "A simple text file.") » true
file.writeTextFile ("C:\\Program Files\\Frontier\\smallXmlFile.xml", table.tableToXml (@user.prefs.fonts))
file.writeTextFile ("C:\\Program Files\\Frontier\\largeXmlFile.xml", table.tableToXml (@websites), blockSize: 1024 * 128) //write in 128KB blocks
file.writeTextFile ("Macintosh HD:Frontier:www:fileWithWindowsEncoding", "This file has Windows-style\rline endings.", lineEnding: "windows")
|
| Notes |
This verb is meant to be used as an easy bottleneck for creating text files which have the proper line endings and character encodings based on the file's type, and the platform Frontier is running on. In most cases, you should call this verb specifying values for only f and s. The rest of the parameters are present to allow you to override the default behavior. The mimeType parameter is used to calculate the default line-endings and text encoding. For text/xml, and text/x-opml, the default line-ending is the line-ending for the platform Frontier is running on, and the default character set is ISO-8859-1 (Latin1/Windows). The text in s is assumed to be in the native character set for the platform Frontier is running on. The characterSet parameter is used to override the default character set. If specified, the text will be converted to the character set you specify before being written to the file. If you're running MacOS, and you specify "windows" for characterSet, then string.macToLatin will be called on the text as it's written to disk. Similarly, if you're running Windows, and you specify "mac" for characterSet, string.latinToMac will be called on the text as it's written to disk. The lineEnding parameter is used to override the default line-ending. If specified, the text will be converted to the line-ending style for the platform you specify, before being written to the file. To write non-text files, or to write text files without line-ending and character set conversion, use file.writeWholeFile. file.writeTextFile supports the same callback scripts that are supported by file.writeWholeFile. Scripts in user.callbacks.fileWriteWholeFile gain control after the file has been written. They take one parameter, the path to the file that was written. The returned value of the callback is ignored.
|
| See Also |
file.writeWholeFile
|