Subscribe Bookmark



Mar 21, 2013

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" );




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


Article Tags