Publication date: 04/12/2021

Get a List of Filenames

To obtain a list of filenames in a specific directory, use the Files In Directory command.

Files In Directory( path, <recursive( 0 | 1 )> );

Both filenames and subdirectory names are returned as shown in the following example:

Files In Directory( "$SAMPLE_DATA" );

{ "2D Gaussian Process", "", ... "Design Experiment", "", ... }

Notice that the files within the Design Experiment subdirectory are not included. And only files in the root $SAMPLE_DATA directory are listed.

To return a list of all file names, add the optional recursive(Boolean) argument to Files In Directory:

Files In Directory( "$SAMPLE_DATA", recursive( 1 ) );

{ "2D Gaussian Process", "", ... "Design Experiment/2x3x4", "Design Experiment/Algorithm", ... }

To get the full pathnames, recurse the directories and concatenate the file paths and file names. The following example loops through each file in the $SAMPLE_DATA directory and subdirectories. The file path is concatenated to each file name.

names = Files In Directory( "$SAMPLE_DATA", recursive( 1 ) );
For( i = 1, i <= N Items( names ), i++,
	names[i] = Convert File Path( "$SAMPLE_DATA" ) || names[i]

{"/C:/Program Files/SAS/JMP/16/Samples/Data/2D Gaussian Process",

"/C:/Program Files/SAS/JMP/16/Samples/Data/", ... }

The Files in Directory command accepts native and POSIX paths, as well as paths using path variables. See Path Variables for more information about working with paths.

Want more information? Have questions? Get answers in the JMP User Community (