directory listing ...

Prev Next

Function Names

directory listing, directory listing recursive

Description

This function creates a table containing the directory listing of the specified path. The table contains following columns: The function directory listing recursive also lists all files in all subdirectories. Unless the listing option is "all", all files inside hidden and system directories are ignored, even if they are stored as regular visible files.

Header Name Contents OS dependent deviations
Path Full path name , ending directory separator symbols Directory separator: Windows: '\', LINUX / MACOS: '/'
Name File or directory name. Directory names end with separator symbols See above
Date Created Date file was created (YYYY-MM-DD),e.g. 2014-12-31
Time Created Time file was created (00:00:00 – 23:59:59)
Date Updated Date file was updated most recently (YYYY-MM-DD)
Time Updated Time file was updated most recently (00:00:00 – 23:59:59)
Directory 'Yes' if entry is a directory name, otherwise 'No'
System 'Yes' if entry is a system file is a system file, otherwise 'No' LINUX / MACOS: Always 'No'
Hidden 'Yes' if hidden, otherwise 'No' LINUX / MACOS: All files beginning with '.' are considered hidden
Archive 'Yes' if archive file, otherwise 'No' LINUX / MACOS: Always "No"
Read Only 'Yes' if read-only, otherwise 'No'
Size File size in bytes

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

1-4

Parameters

No.TypeDescription
1
input
string name of destination table

The directory listing will be put into this table, with header names as lsited above. If the table is not yet existing, then it will be created. Existing tables will be initialized first.

Opt. 2
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. 3
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. 4
input
string search option

One of the following:

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

Default value: files and directories

Return value

TypeDescription
numeral Entry count

Total number of files and/or directories found. -1 = Error (e.g. invalid path). Table will be empty in this case.

Examples

               define procedure ( listing, {{ description, string }, {count, numeral}} )
               {
                       echo( new line, description[], "    (Containing ", count[], " entries)" );
                       table process( list, echo( [Date Created]," ",[Time Created]," ", [Path], [Name] ) );
               }

               // Both listings are equivalent.

               path[] = system info[bin directory];
               echo("Using following main path: ", path[] );

               rv[] = directory listing( list, path[] );
               listing( "All files in specified subdirectory", rv[]);

               rv[] = directory listing( list, path[] + "\L*,B*" );
               listing( "All directories and files brginning with L or B", rv[]);
               echo;

               rv[] = directory listing( list, path[], "*", directories );
               listing( "All subdirectores. Note: Use '*', not '*.*'.", rv[]);
               echo;

               rv[] = directory listing( list, path[]+"\lib", "*.txt" );
               listing( "All files with type in lib subdirectory'.txt'", rv[]);

               rv[] = directory listing recursive( list, path[], "*.b4p,*.txt" );
               listing( "All .b4p and .txt files in current and subdirectories", rv[]);

               rv[] = directory listing recursive( list, "C:\dk3@ç%45*\" );
               listing( "Empty table, -1 returned due to invalid path name", rv[]);

Output

Using following main path: C:\Program Files\b4p

All files in specified subdirectory    (Containing 11 entries)
2024-10-19 15:58:03 C:\Program Files\b4p\B4P Reference Manual.b4p
2024-10-19 15:58:03 C:\Program Files\b4p\B4P Style Themes.xlsx
2024-10-19 15:58:03 C:\Program Files\b4p\B4P.exe
2024-10-19 15:58:03 C:\Program Files\b4p\b4picon.ico
2024-10-19 15:58:03 C:\Program Files\b4p\Install.txt
2024-10-19 15:58:03 C:\Program Files\b4p\lib\
2024-10-19 15:58:03 C:\Program Files\b4p\List of Locales.csv
2024-10-19 15:58:03 C:\Program Files\b4p\Setup.exe
2024-10-19 15:58:03 C:\Program Files\b4p\vcruntime140.dll
2024-10-19 15:58:03 C:\Program Files\b4p\vcruntime140_1.dll
2024-10-19 15:58:03 C:\Program Files\b4p\weblib\

All directories and files brginning with L or B    (Containing 6 entries)
2024-10-19 15:58:03 C:\Program Files\b4p\B4P Reference Manual.b4p
2024-10-19 15:58:03 C:\Program Files\b4p\B4P Style Themes.xlsx
2024-10-19 15:58:03 C:\Program Files\b4p\B4P.exe
2024-10-19 15:58:03 C:\Program Files\b4p\b4picon.ico
2024-10-19 15:58:03 C:\Program Files\b4p\lib\
2024-10-19 15:58:03 C:\Program Files\b4p\List of Locales.csv


All subdirectores. Note: Use '*', not '*.*'.    (Containing 2 entries)
2024-10-19 15:58:03 C:\Program Files\b4p\lib\
2024-10-19 15:58:03 C:\Program Files\b4p\weblib\


All files with type in lib subdirectory'.txt'    (Containing 1 entries)
2024-10-19 15:58:03 C:\Program Files\b4p\lib\Interactive Help.txt

All .b4p and .txt files in current and subdirectories    (Containing 20 entries)
2024-10-19 15:58:03 C:\Program Files\b4p\B4P Reference Manual.b4p
2024-10-19 15:58:03 C:\Program Files\b4p\Install.txt
2024-10-19 15:58:03 C:\Program Files\b4p\lib\B4P Init.b4p
2024-10-19 15:58:03 C:\Program Files\b4p\lib\Console Library.b4p
2024-10-19 15:58:03 C:\Program Files\b4p\lib\help\Help Access Local Docs.txt
2024-10-19 15:58:03 C:\Program Files\b4p\lib\help\Help Access Online Docs.txt
2024-10-19 15:58:03 C:\Program Files\b4p\lib\help\Help Basic Commands.txt
2024-10-19 15:58:03 C:\Program Files\b4p\lib\help\Help Interactive.txt
2024-10-19 15:58:03 C:\Program Files\b4p\lib\help\Help Start.txt
2024-10-19 15:58:03 C:\Program Files\b4p\lib\help\Help System Commands.txt
2024-10-19 15:58:03 C:\Program Files\b4p\lib\help\Help Tables.txt
2024-10-19 15:58:03 C:\Program Files\b4p\lib\help\Help Variables.txt
2024-10-19 15:58:03 C:\Program Files\b4p\lib\help\Shortcuts.txt
2024-10-19 15:58:03 C:\Program Files\b4p\lib\Interactive Help.txt
2024-10-19 15:58:03 C:\Program Files\b4p\lib\Office Library.b4p
2024-10-19 15:58:03 C:\Program Files\b4p\lib\Short Commands Library.b4p
2024-10-19 15:58:03 C:\Program Files\b4p\lib\Style Library.b4p
2024-10-19 15:58:03 C:\Program Files\b4p\lib\Support Library.b4p
2024-10-19 15:58:03 C:\Program Files\b4p\lib\Utility Library.b4p
2024-10-19 15:58:03 C:\Program Files\b4p\lib\Zip Library.b4p

Empty table, -1 returned due to invalid path name    (Containing -1 entries)
Try it yourself: Open LIB_Function_directory_listing.b4p in B4P_Examples.zip. Decompress before use.

See also

advanced directory listing
count files