Syntax
wfname=writetextfile([fname,txt])
Input Parameter
fname : | | filenname for desktop or full path |
txt : | | ascii text |
Output Parameter
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
- fname: This is the filename for the desktop or the full path where the text file will be saved. If a full path is not provided, the function will assume the file is to be saved on the desktop.
- txt: This is the ASCII text that will be written into the file. If not provided, the current date in the format 'yyyy-MM-dd' will be used as the default text.
Output Results
- wfname: This is the full filename where the text has been written.
Algorithm Steps
- 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.
- The text is converted to a character array using
char(uint8(txt))
.
- 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.
- 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.
- If the file cannot be opened, an error is thrown.
- The text is written to the file using
fwrite
with 'uint8' data type.
- The file is closed using
fclose
.
- 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