search files ...

Prev Next

Function Names

search files, search files recursive

Description

Searches the disk for a particular files and/or directories and returns the full paths.

  • search files recursive searches recursively. Recursive strategy: If a subdirectory is encountered, the files inside the subdirectory will be searched immediately before continuing with the next entry.
  • search files searches in the specified directory.

Note:Files searched are not guaranteed to be in any deterministic order, e.g. alphabetic order. Ordering behaviors differ among operating systems.

The resulting file names contain the path name as specified. Example. If ".\sudir" is specified, then this (relative) path name will be added to all file and directory names returned. Files listed in the current directory contain no path names in front.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

0-4

Parameters

No.TypeDescription
Opt. 1
input
string drive or path name

Specify a disk drive (e.g. C:\) or a path name (/usr/local, or \\server_name\path_name\...). If no additional parameters are provided, then the path name may also contain a file name (to list 1 file) or matching pattern to list specific files.
Note: Wildcard symbols are supported here for the file name, but not for the path name (OK: C:\Subdir\*.txt, Not OK: C:\Sub*\*.txt)

Default value: Current working directory
Opt. 2
input
string pattern name

Specify a disk drive (e.g. C:\) or a path name (/usr/local, or \\server_name\path_name\...). If no additional parameters are provided, then the path name may also contain a file name (to list 1 file) or matching pattern to list specific files.
Note: Wildcard symbols are supported here for the file name, but not for the path name (OK: C:\Subdir\*.txt, Not OK: C:\Sub*\*.txt)

Default value: * (all files)
Opt. 3
input
numeral Match count limitation

<0 Search for all matches and return set containing all names. A set is also used if only one item has been found.
0 Search for first matching file / directory name and return as string (and not in a set)
>0 First for specified number file / directory names, then stop. All names are put into sets.

Default value: -1 (no limit)
Opt. 4
input
string search option

One of the following:

files Files only
directories Directories only
files and directories Foth files and directoreies (default)
all Also includes hidden and system files

Default value: files and directories

Return value

TypeDescription
string
set
Identified names

All file and directory names found as specified.

Examples

               echo("All files in a directory        : ", search files( "C:\Program Files\B4P\" ), new line );

               echo("All files : ", search files( ".\", "*.b4p"      ) );
               echo("1st file only (as string)      : ", search files( ".\", "*.b4p", 0   ) );
               echo("1st file only (in set): ", search files( ".\", "*.b4p", 1   ) );
               echo("1st file only (as string)      : ", search files( "..\", "*", 0   ), new line ); // One directory up
               echo("All subdirectories              : ", search files( "C:\Program Files\B4P", "*", -1, directories   ) );
               echo("All .b4p/.txt recursively       : ",
                       search files recursive( "C:\Program Files\B4P", "*.txt,*.b4p", -1, files  ) );

Output

All files in a directory        : {'C:\Program Files\B4P\B4P Reference Manual.b4p','C:\Program Files\B4P\B4P Style Themes.xlsx','C:\Program Files\B4P\B4P.exe','C:\Program Files\B4P\b4picon.ico','C:\Program Files\B4P\Install.txt','C:\Program Files\B4P\List of Locales.csv','C:\Program Files\B4P\Setup.exe','C:\Program Files\B4P\vcruntime140.dll','C:\Program Files\B4P\vcruntime140_1.dll'}

All files : {'Build_Docu.b4p','Example_Program.b4p','interactive.b4p','Make_Index.b4p','Start B4P here.b4p','table_lookup_smart_new.b4p'}
1st file only (as string)      : Build_Docu.b4p
1st file only (in set): {'Build_Docu.b4p'}
1st file only (as string)      : ..\Analzyer.zip

All subdirectories              : {'C:\Program Files\B4P\lib','C:\Program Files\B4P\weblib'}
All .b4p/.txt recursively       : {'C:\Program Files\B4P\B4P Reference Manual.b4p','C:\Program Files\B4P\Install.txt','C:\Program Files\B4P\lib\B4P Init.b4p','C:\Program Files\B4P\lib\Console Library.b4p','C:\Program Files\B4P\lib\help\Help Access Local Docs.txt','C:\Program Files\B4P\lib\help\Help Access Online Docs.txt','C:\Program Files\B4P\lib\help\Help Basic Commands.txt','C:\Program Files\B4P\lib\help\Help Interactive.txt','C:\Program Files\B4P\lib\help\Help Start.txt','C:\Program Files\B4P\lib\help\Help System Commands.txt','C:\Program Files\B4P\lib\help\Help Tables.txt','C:\Program Files\B4P\lib\help\Help Variables.txt','C:\Program Files\B4P\lib\help\Shortcuts.txt','C:\Program Files\B4P\lib\Interactive Help.txt','C:\Program Files\B4P\lib\Office Library.b4p','C:\Program Files\B4P\lib\Short Commands Library.b4p','C:\Program Files\B4P\lib\Style Library.b4p','C:\Program Files\B4P\lib\Support Library.b4p','C:\Program Files\B4P\lib\Utility Library.b4p','C:\Program Files\B4P\lib\Zip Library.b4p'}
Try it yourself: Open LIB_Function_search_files.b4p in B4P_Examples.zip. Decompress before use.

See also

count files
directory listing