LMS. - LM Studio Interface

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > AI - Artificial Intelligence Commands > LMS. - LM-Studio Commands >

LMS. - LM Studio Interface

LMS.GenerateUniqueFilename - Creates a unique filename

Previous Top Next


MiniRobotLanguage (MRL)

 

LMS.GenerateUniqueFilename Command

Generate Unique Filename

 

Intention

 

This utility command, also known by its alias LMS.guf, provides a safe way to generate a filename that does not conflict with any existing files in the same directory.

 

It works by taking a desired file path (e.g., "C:\logs\output.txt") and checking if it exists. If it does, it appends a numeric suffix (e.g., "_0001") before the extension until an unused name is found (e.g., "C:\logs\output_0001.txt"). This is extremely useful for preventing data loss when saving log files, reports, or downloads.

 

Syntax

 

LMS.Generate Unique Filename|P1|[P2]

LMS.guf|P1|[P2]

 

Parameter Explanation

 

P1 - (Required) The base file path (including name and extension).

P2 - (Optional) The variable to store the resulting unique file path. If omitted, the default variable is used (not common).

 

Example

 

'**********************************************

' LMS.generateuniquefilename - Sample

'**********************************************

'

$$BasePath = "C:\AppData\MyDownload.zip"

'

' Call the function using its alias "guf"

LMS.guf|$$BasePath|$$UniquePath

'

' $$UniquePath will contain "C:\AppData\MyDownload.zip" if it does not exist.

' If it *does* exist, it will contain "C:\AppData\MyDownload_0001.zip"

' If that also exists, it will try "_0002", and so on.

MBX.Info|The unique file path is: $$UniquePath

ENR.

 

Remarks

 

If the file path in P1 does not contain an extension, ".tmp" will be automatically appended and used as the extension.

The function will try up to 9,999 suffixes. If a unique name cannot be found (e.g., "file_9999.txt" already exists), the function will return an empty string.

This command is an alias for the internal `LMS_GenerateUniqueFilename` function.

 

See also:

 

    LMS.ask - Basic AI Query

    LMS.askex - Extended AI Query