FIL. - File-Commands

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Filesystem-Commands > FIL. - File-Commands >

FIL. - File-Commands

FIL.Generate next numbered Name 

Previous Top Next


MiniRobotLanguage (MRL)

 

FIL.Generate next numbered Name

Generates unique, sequentially numbered file name

 

 

Intention

 

FIL.Generate next numbered Name - Generates a sequentially numbered file name and checks for its existence, incrementing the number until a non-existing file name is found. You can specify the start number and the number Format, means number of leading zeroes.

The FIL.Generate next numbered Name command is used to create a sequentially numbered file name based on a provided path template (P1), starting number (P2), and number formatting (P3). The command checks if a file with the generated name exists; if it does, the number is incremented until a non-existing file name is generated.

 

This command is useful for creating file names for a sequence of files without overwriting existing ones.

The path template must contain a "?" as a placeholder for the formatted number. The placeholder will be replaced by the generated number in the file name.

The number formatting applies leading zeroes based on the value provided in P3.

The search for a non-existing file name starts from the number provided in P2 and increments if a file with the same name already exists.

 

The `Get_Next_Numbered_Name` function is designed to generate a unique filename. It takes in three parameters, P4 contains the result.

 

1. `P1`: This parameter can either be a file type (like "bmp", "png", etc.) or a complete filename with a "?" as a placeholder for numbers.
    If it's a complete filename, the function will use it as a template to generate the new filename.
    If it's a file type, the function will generate a filename in the format of "?exeloc\Temp_?.filetype" in the current executable's directory.

 

2. `P3`: This parameter specifies the number of digits for the number in the filename. If it's 0 or less, it will be set to 4.
    The number in the filename will be formatted with leading zeros to match this length.

 

3. `P2` (optional): This parameter specifies the starting number for searching for an available number for the filename.
    If it's not provided (i.e., it's 0), the function will start searching from 0.

 

The function works by first checking the format of `P1` and preparing a filename template.
If `P1` is a complete filename with a "?", it will be used as the template and the file type will be extracted from it.
If `P1` is a file type, a template in the format of "Temp_?.filetype" will be generated.

 

If the filename template doesn't contain a "?" but contains a number,
the function will extract the number and replace it with a "?", and use the extracted number as the starting number for searching.

 

If a new filename is successfully generated, it will be returned by the function. If not, the function will return an empty string.

 

 

Syntax

 

 

FIL.Generate next numbered Name|P1|P2[|P3][|P4]

FIL.gen|P1|P2[|P3][|P4]

 

 

Parameter Explanation

 

P1 - The path template with a "?" placeholder to be replaced by the formatted number. if its just an extension like "txt" or "png" then a TMP-File will be created at ?exeloc\.

P2 - (optional) The starting number for the search. Defaults to "1" if omitted.

P3 - (optional) The number of digits for formatting. No formatting is applied if it is less than 2 or omitted.

P4 - (optional) The name of the variable where the result will be stored. If omitted or invalid, the result is placed on the Top of Stack (TOS).

 

 

 

Example

 

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

' FIL.gen.-Sample

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

$$PRO=neural network beautiful golden girl Galaxy robot digital photorealistic NC-1701 enterprise

' Use Image Register 0

$$IMR=0

FOR.$$STP|1|25

  $$FIR=?path\Sample Pics\Testresult_?.png

  FIL.gen|$$FIR|1|0|$$FIL

  SDL.gtf|$$PRO|$$FIL

  ANA.Load|$$IMR|$$FIL

  $$TXT=SPR/SDO. generated: $$STP Steps

  $$COA=&HFFFFFF

  $$COB==&H0

  $$BGC=-2

  $$XPA=30

  $$YPA=450

  ANA.PrintAt|$$IMR|$$TXT|$$COA|$$BGC|$$XPA|$$YPA|24

  ANA.PrintAt|$$IMR|$$TXT|$$COB|$$BGC|($$XPA+1)|($$YPA+2)|24

  DBP.Loaded in IR:$$IMR -> $$FIL

  ANA.Show|$$IMR

NEX.

ENR.

 

 

 

 

Remarks

 

  Ensure that the process has read permissions to the specified file path to check for file existence.

  Be aware that if the directory contains a very large number of files, it might take longer to find a non-existing file name.

 

 

Limitations:

 

-

 

 

See also: