cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
WoHNY
Level III

JMP 16: Script to open most recent .csv file in a folder.

I have been using the path = Pick File(); command to manually select the file to import into a data table. Can you script a command to import the most recent .csv file in a folder to a data table? There is only one worksheet in these files.

4 REPLIES 4

Re: JMP 16: Script to open most recent .csv file in a folder.

Did you search Functions in Help > Scripting Index and examine the File group of functions?

 

 

file.PNG

 

You could base a script on the Creation Date() or the Last Modification Date() functions.

WoHNY
Level III

Re: JMP 16: Script to open most recent .csv file in a folder.

Mark: Thank you for the response. I wasn't aware of the Scripting index under help so that is big help going forward. I was referencing a pdf version of a JMP15 Scripting Guide that is not search friendly. One issue I have with the file name is that it includes the time stamp at the end of the name, so it is dynamic. The format is FileName_YYYYMMDDHHMM.csv. I will stick with PickFile for now and experiment with the LastModificationDate function. Thanks again.

Re: JMP 16: Script to open most recent .csv file in a folder.

You can match the file name with the Contains() function if you want to ignore the time stamp.

Re: JMP 16: Script to open most recent .csv file in a folder.

I just happen to have had this need in the past, and luckily saved a script just in case...

You'll need to change the strings on line 2 and 3.

Names Default To Here( 1 );
searchext = "jmp"; //extension to look for
searchfolder = "$DESKTOP"; //place to search

lstExtensions = {};
lstDates = {};
lstFiles = Files In Directory( searchfolder );
For Each( {i, j}, lstFiles,
	lstExtensions[j] = Char( Right( i, 3 ) );
	lstDates[j] = As Date( Creation Date( searchfolder || "/" || Char( i ) ) );
);
dt = New Table( "Files",
	New Column( "Name", character, set values( lstFiles ) ),
	New Column( "ext", character, set values( lstExtensions ) ),
	New Column( "Date", numeric, set values( Matrix( lstDates ) ) )
);

dt << Select where( :ext != searchext );
dt << Delete Rows;

newest = Col Min( :Date );
newfile = searchfolder || "/" || :Name[dt << Get Rows Where( :Date == newest )][1];
Close( dt, no save );
Open( newfile );