Lasso Soft Inc. > Home

[ file->openTruncate ]

Method

The [file->openTruncate] method can be called on a [file] object to open a file for truncating and writing. If a path is already stored in the [file] object, it can be called with no parameters. It can also be called with a string specifying the path to a file. If it is called with a path to a file, that new path becomes the path for the [file] object, overriding any previous path.

If [file->openTruncate] is called with a file path, it can also take an optional boolean parameter that specifies whether or not to create the file if it doesn't already exist. The default is true which means the file will be created if it does not already exist.

Please note that when this method is called, the contents of the specified path will be deleted.

  • Syntax
local(f) = file(...)
#f->openTruncate

local(f) = file
#f->openTruncate('/path/to/file.txt')

local(f) = file
#f->openTruncate('/path/to/file.txt', false)
Examples
  • Beginner

Set the contents of a file

The code below sets the contents of a file to "Manure, I hate manure." It removes any previous content the file may have contained.

Code

local(my_file) = file
handle => {#my_file->close}
#my_file->openTruncate('test.txt')
#my_file->writeString('"Manure. I hate manure."')

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft