file browser

Prev Next

Function Names

file browser

Library

Support Library

Description

This function provides interactive file browsing (using the table features of table view()) where the user will see directory and file names, file type, size and date and timestamp of last modification. Optionally, the different file types appear in their characteristic colors, e.g. blue for (Microsoft Word) documents.

While browing the files, following navigation keys are available:

Key Function
Move up
Move down
Move left
Move right
Pg up 1 screen page up
Pg dn 1 screen page down
Home Move to 1st column
End Move to last column
Ctrl-Home Move to 1st row
Ctrl-End Move to last row
Ctrl- ↑ Reduce number of screen lines to display contents
Ctrl- ↓ Increase number of screen lines to display contents
Ctrl- ← Reduce column width
Ctrl- → Increase column width
Ctrl-C Copy cell contents into clipboard (Pushing Ctrl-C twice in a row stops program execution)
F1 Quick on-screen help for the available navigation functions
Enter key Enter a sub-folder or, on the 1st row, the parent folder (..)
Escape key Stop program execution
Visible characters Specify a path or directory name directly to change directory. Just start typing and a prompt to choose a directory will occur automatically.

Hint: Use the drag and drop feature. If you have a file browser open, then click on the folder symbol to choose, hold the mouse key pressed and drop it into the console with the running B4P program. The drop action actually types the full path of the selected directory. Press 'Enter' to change the directory. If the directory cannot be found or is not accessible, then no change takes place.

Call as: procedure or function

Restrictions

Under normal conditions, the 'Support Library' is loaded automatically, so no 'include(...)' call is needed.
Not suitable for batch processing

Parameter count

1-4

Parameters

No.TypeDescription
Opt. 1
input
string Prompt

The prompt text will be displayed at the bottom of the table. UNICODE PUA2 characters (like &yellow; for yellow texdt) are allowed here to add visual effects.

If the prompt consists of two rows, separated with a new line character, then the first line will be displayed above the table (instead of a standard table header info) and the 2nd line will be used as the prompt.

Default value: Current path on 1st row, standard prompt below the table
Opt. 2
input
string Path

Specify an existing path. Relative paths such as specifying subdirectories, '..' for parent folder, '.' for current folder, etc. are supported. Wildcards are not allowed here.

Default value: . (current folder)
Opt. 3
input
string Pattern

Specify the pattern to be applied for the file names. Folder names are not affected by this. For exapmle, specify "*.xlsx,*.xlsm" to include all Excel files with and without macros.

Note: Under Windows, cases for pattern matching are ignored, but not for LINUX or MACOS. DO ignore case, see 4th function parameter.

Default value: * (all files)
Opt. 4.
input
set Options

The parameters set may contain the following options.

files only Only files will be listed. When pushing 'Enter', the chosen file name will be returned without the path name.
colors File names of common types will be colored, e.g. spreadsheets in green, presentations in red, PDF files in pink, etc.
file names ignore case Applicable to LINUX and MACOS: Comparing files with matching pattern provided with the 3rd function paramter will ignore upper/lower case. Under Windoes, cases are ignored anyway.

Following options, also provided in table view(), are also supported here:

full row cursor The enire row will be marked
ignore case The entered character will be compared with the return characters, but ignoring upper/lower case. Letters returned are in upper case.
no deco No color features like background zebra pattern
no input The table will be displayed, but no prompt will show up and no input will be requested. Suitable for passive display.
alt screen The table will be displayed on an alternative screen. The previous screen contents with its history will resume after done viewing.

Default value: {} (empty set) - No options specified

Return value

TypeDescription
string Chosen file

An empty string (blank) is returned if the file browser is left by pressing 'Escape'. If 'Enter' is pressed on a file name, then one of the following cases apply: * If the 4th funtion parameter contains 'files only' as a setting which disables navigation through directories, then only the file name will be returned. * Otherwise, the full path with the file name will be returned.

Examples


       file name[] = file browser( "Select an Excel file: ", ".", "*.xlsx,*.xlsm", { colors, file names ignore case } );
       echo("Good job. The chosen file name is: ", file name[] );

See also

dir
table view
directory listing