cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
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

Last Modified: Oct 18, 2016 9:31 PM