writetextfile

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - File handling
Introduced first in SolidGeometry 5.2, Creation date: 2022-03-10, Last change: 2025-09-15

writes a character string into a text file



See Also: readtextfile

Example Illustration

 missing image of writetextfile(fname,txt)

Syntax

wfname=writetextfile([fname,txt])

Input Parameter

fname: filenname for desktop or full path
txt: ascii text

Output Parameter

wfname: full filename

Examples


writetextfile('test','this is a test')




Copyright 2022-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This function, writetextfile, is designed to write a character string into a text file. It is part of the SolidGeometry library, version 5.2, and was created by Tim C. Lueth in 2022.

Input Parameters

Output Results

Algorithm Steps

  1. The function begins by retrieving the filename (fname) and text (txt) from the input arguments using the getfuncparams function. If txt is not provided, it defaults to the current date.
  2. The text is converted to a character array using char(uint8(txt)).
  3. If the filename does not contain a file separator, it is assumed to be a desktop file, and the desktopdir function is used to get the full path.
  4. The file is opened for writing in text mode with UTF-8 encoding using fopen. The mode 'wt+' is used to open the file for writing and reading, and the file is created if it does not exist.
  5. If the file cannot be opened, an error is thrown.
  6. The text is written to the file using fwrite with 'uint8' data type.
  7. The file is closed using fclose.
  8. The function returns the full filename (wfname).

Example

To write the text "this is a test" into a file named "test" on the desktop, you would call the function as follows:

writetextfile('test', 'this is a test')
Algorithm explaination created using ChatGPT on 2025-08-19 01:16. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21