AIG. - AI Google Gemini Integration

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

AIG. - AI Google Gemini Integration

AIG.GenerateUniqueFilename

Previous Top Next


MiniRobotLanguage (MRL)

 

AIG.Generate UniqueFilename
Generate a Unique Filename for File Operations

 

Intention

 

GenerateUniqueFilename Command: Creating Unique File Identifiers
 
The GenerateUniqueFilename command generates a unique filename based on a provided base name, ensuring that file operations within your scripts avoid conflicts or overwrites.

This utility is particularly useful when saving temporary files, API responses, or logs in the AIG framework, providing a reliable way to create distinct filenames dynamically. It simplifies file management by automatically handling naming conventions and uniqueness, making it an essential tool for robust automation scripts.

It’s part of the AIG - Google Gemini API suite, supporting file-related operations.

 

What is the GenerateUniqueFilename Command?

 

The GenerateUniqueFilename command takes a base filename as input and produces a unique filename by appending a distinguishing element (e.g., a timestamp or random string) via an internal utility function.

It processes the input to ensure validity—removing redundant dots (e.g., converting "file..txt" to "file.txt") and adding a default ".tmp" extension if none is provided or if the filename ends with a dot. The resulting unique filename can be stored in a variable or placed on the Top of Stack (TOS) for further use in your script.

Unlike other AIG commands tied to the Google Gemini API, this is a standalone utility focused on file handling, making it versatile for general scripting needs beyond AI interactions.

 

Why Do You Need It?

 

Generating unique filenames is valuable for:

Avoiding Overwrites: Prevent accidental overwriting of existing files during automated tasks.

Temporary Files: Create safe filenames for temporary storage, such as caching AI responses or logs.

Organization: Maintain a clean file system by ensuring each file has a distinct name.

Script Reliability: Enhance script robustness by eliminating filename conflicts in multi-step operations.

 

How to Use the GenerateUniqueFilename Command?

 

Provide a base filename as the first parameter (e.g., "report" or "data.txt"). The command ensures the filename is valid and appends a unique identifier.

Optionally, specify a variable to store the result. If omitted, the unique filename is pushed to the TOS. The generated filename can then be used with file operations like writing AI responses or saving keys (e.g., via AIG.Save Key).

Key behaviors include:

If no extension is provided (e.g., "log"), it adds ".tmp" (resulting in "log_20250319.tmp").

If the filename ends with a dot (e.g., "file."), it appends "tmp" (resulting in "file_20250319.tmp").

Removes redundant dots (e.g., "file..txt" becomes "file_20250319.txt").

 

Example Usage

 

' Generate a unique filename with a variable

AIG.Generate UniqueFilename|report|$$FIL

DBP.Unique Filename: $$FIL

' Stack-based retrieval

AIG.Generate UniqueFilename|data.txt

POP.$$NAM

DBP.Generated Name: $$NAM

' Use with file operation

AIG.Generate UniqueFilename|response|$$OUT

AIG.Ask|What is AI?|$$RES

FIO.Write File|$$OUT|$$RES

DBP.Saved AI response to: $$OUT

 

These examples show generating filenames for reports, simple text files, and saving AI responses, with results either stored or stacked.

 

Illustration

 

┌──────────────────────┐

│ Base Filename        │

├──────────────────────┤

│ "report"             │

└──────────────────────┘

 ↓

┌──────────────────────┐

│ Unique Filename      │

├──────────────────────┤

│ "report_20250319.tmp"│

└──────────────────────┘

Transforming a base filename into a unique identifier for safe file operations.

 

Syntax

 

AIG.Generate UniqueFilename|P1[|P2]

 

Parameter Explanation

 

P1 - (Required) The base filename or prefix (e.g., "log", "data.txt") to make unique.

P2 - (Optional) The variable where the unique filename will be stored. If omitted, the result is placed on the Top of Stack (TOS).

 

Example

 

' Generate a filename for a log

AIG.Generate UniqueFilename|logfile|$$LOG

DBP.Log will be saved as: $$LOG

' Handle a filename with dots

AIG.Generate UniqueFilename|test..dat|$$FIL

DBP.Cleaned and Unique: $$FIL

' Stack-based with no extension

AIG.Generate UniqueFilename|temp

POP.$$TMP

DBP.Temporary File: $$TMP

ENR.

 

Remarks

 

- The uniqueness mechanism typically appends a timestamp or random string, though exact implementation depends on the GenerateUniqueFilename_SL function.

- Does not specify a directory; use with a path if needed (e.g., "?exeloc\data.txt").

- The command ensures a valid filename but does not create the file itself—pair with file I/O commands as needed.

 

Limitations

 

- Does not check if the generated filename already exists in the file system; uniqueness is based on the generation method.

- Limited to basic filename processing; complex paths or special characters may require additional handling.

- Fails if more than two parameters are provided, triggering a parameter count error.

 

See also:

 

AIG.Save Key

AIG.Ask

Original Filename Generator