choose recent file

Prev Next

Function Names

choose recent file

Library

Utility Library

Description

This function will either identify the most recent file according to a specified ordering criteria.

Call as: function

Restrictions

Under normal conditions, the 'Utility Library' is loaded automatically, so no 'include(...)' call is needed.

Parameter count

5

Parameters

No.TypeDescription
1.
input
string Prompt text

A prompt text is needed if the count (provided in the last function parameter) is not 1. The prompt will be displayed if needed so you can select from of the n recent files displayed.

2.
input
string Path name

Specify the path name to the directory where the files to be searched are located. No wildcards are supported here.

3.
input
string File name pattern to match

Specify file name pattern where the file name part may contain wildcard symbols such as '*' and '?'. The pattern will be used to obtain a listing of matching files which will then be prioritzed by the ordering criteria. Exammple: "b4p*.txt" covers all files beginning wtih "b4p" and ending with file type ".txt".

4.
input
string Ordering criteria

One of the following values apply:

oldest Selects the oldest file or list n (count) oldest files you can choose from.
newest Selects the newest file or list n (count) newest files you can choose from.
first Selects the first file or list the first n (count) files in alphabetical order you can choose from.
last Selects the last file or list the last n (count) files in alphabetical order you can choose from.
biggest Selects the biggest file (file size) or list the n biggest files you can choose from.7
smallest Selects the smallest file (file size) or list the n smallest files you can choose from.7

5.
input
numeral Count

Valid range: 1-35
If 1 is chosen, then no menu will be displayed because the first match according to the prioritization (e.g. newest file) is returned.

Return value

TypeDescription
string Identified file name

The file name contains no directory path. If no file has been found, then a blank string is returned.

Exceptions

If no file is found, and verbose level is not 'quiet', then an error message will warn you about no files found. You have the choice to stop or continue

Examples

       a[] = choose recent file( "", "Examples\", "*table*.b4p", first, 1 ); // No user interaction
       echo("First file in alphabetic order containing 'table' is ", a[] );

       a[] = choose recent file( "", "Examples\", "*table*.b4p", last, 1 ); // No user interactino
       echo("First file in alphabetic order containing 'table' is ", a[] );

       a[] = choose recent file( "Please choose one of the newest files: ", "Examples\", "*.b4p", newest, 5 );

       echo("Chosen file is: ", a[] );

Output

First file in alphabetic order containing 'table' is REF_Features_Table_columns.b4p
First file in alphabetic order containing 'table' is REF_Function_with_table.b4p
Found 382 files.

Please choose one of the newest files:
     1 :  REF_Function_variable_to_json.b4p         (2020-10- 3 17:57:34      0 kB)
     2 :  REF_Function_vertical.b4p                 (2020-10- 3 17:57:34      0 kB)
     3 :  REF_Function_week.b4p                     (2020-10- 3 17:57:34      0 kB)
     4 :  REF_Function_weekday.b4p                  (2020-10- 3 17:57:34      0 kB)
     5 :  REF_Function_while.b4p                    (2020-10- 3 17:57:34      0 kB)
Please select: 3
Chosen file is: REF_Function_week.b4p
Try it yourself: Open LIB_Function_choose_recent_file.b4p in B4P_Examples.zip. Decompress before use.

See also

directory listing