cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Get the free JMP Student Edition for qualified students and instructors at degree granting institutions.
Choose Language Hide Translation Bar
View Original Published Thread

Craige_Hales
Super User
Files In Directory

This example uses Files In Directory to get a list of all the files in a directory.  It then looks for all the .jmp files, opens (and later closes) them one by one, making a summary table along the way.  The $sample_data directory has sub-directories which will be in the list but are skipped by the EndsWith test.  EndsWith is case sensitive; you might want EndsWith(LowerCase(filename), ".jmp") to get the files that end in .JMP and .jmp.

Files In Directory does not need the trailing /, but doesn't mind it either.  But the trailing / is important when the file names in the list are concatenated to the directory.  JMP takes care of the windows vs mac / and \ issues.

directory = "$sample_data/";

fileNames = Files In Directory( directory );

summary = New Table( "summary", New Column( "name", character ), New Column( "rows", numeric ) );

For( iFile = 1, iFile <= N Items( fileNames ), iFile++,

  filename = fileNames[iFile];

  If( Ends With( filename, ".jmp" ),

    dt = Open( directory || filename );

    summary << addrows( 1 );

    summary:name = filename;

    summary:rows = N Rows( dt );

    Close( dt, "nosave" );

  );

);

10722_FilesInDirectory.PNG

There is a recursive option if you want those files too...


10723_FilesInDirRecursive.PNG