- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
JSL script Open latest version file in the folder
Hi,
I want to automate the script where it will automatically open the latest file based on latest date in the file name and latest modified date in a specific folder which shown in the picture below. How can I do this?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL script Open latest version file in the folder
You can use
Files in Directory()
to get all of the files in a directory.
And then using Ian's code, you can loop across all of the files and get the file with the latest date in it's name,
and/or, you can use the
Last Modification Date()
function to find the last time each specific file was modified
Names Default To Here( 1 );
Format(
Last Modification Date(
"$SAMPLE_DATA/Big Class.jmp"
),
"ddmonyyyy:h:m:s"
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL script Open latest version file in the folder
Looks like there are two requirements here - To get the file creation date (encoded in the file name), and to get the last time this file was modified (from the operating system).
For the first of these, you could try starting from the JSL below:
NamesDefaultToHere(1);
// Given a file name constructed in a particular way, returns the encoded creation date
getDateFromFileName =
Function({fName}, {Default Local},
pieces = Words(fName, "-");
pieces[1] = Substr(pieces[1], 8, 2); // Get the 'day'
pieces[3] = Substr(pieces[3], 1, 4); // Get the 'year'
dt = Num(Informat(pieces[1]||pieces[2]||pieces[3], "DDMonYYY")); // Get the JMP datetime from the pieces
);
fName = "Testing01-Nov-2018_.xlsx";
dt = getDateFromFileName(fName);
Note that how robust this kind of code is will depend crucially on what you can (and can't) safely assume about how the file name is constructed.
To get the last time a file was modified, you may need to look at 'Run Program' (search for this in 'Help > Scripting Index').
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL script Open latest version file in the folder
You can use
Files in Directory()
to get all of the files in a directory.
And then using Ian's code, you can loop across all of the files and get the file with the latest date in it's name,
and/or, you can use the
Last Modification Date()
function to find the last time each specific file was modified
Names Default To Here( 1 );
Format(
Last Modification Date(
"$SAMPLE_DATA/Big Class.jmp"
),
"ddmonyyyy:h:m:s"
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL script Open latest version file in the folder
Many thanks Jim - I overlooked 'Last Modifcation Date()', so it's good to know about it . . .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL script Open latest version file in the folder
The File - Import Multiple file command can add a column or filter based on the last modified date. You could point it at the folder, read in all the data and then just keep the file with the newest date.
Multiple File Import(
<<Set Folder( "C:\Testing\" ),
<<Set Name Filter( "*.*;" ),
<<Set Name Enable( 0 ),
<<Set Size Filter( {162, 4814056} ),
<<Set Size Enable( 0 ),
<<Set Date Filter( {3606508609.82052, 3623302732.269} ),
<<Set Date Enable( 0 ),
<<Set Add File Name Column( 0 ),
<<Set Add File Size Column( 0 ),
<<Set Add File Date Column( 1 ),
<<Set Import Mode( "CSVData" ),
<<Set Charset( "Best Guess" ),
<<Set Stack Mode( "Stack Similar" ),
<<Set CSV Has Headers( 1 ),
<<Set CSV Allow Numeric( 1 ),
<<Set CSV First Header Line( 1 ),
<<Set CSV Number Of Header Lines( 1 ),
<<Set CSV First Data Line( 2 ),
<<Set CSV EOF Comma( 1 ),
<<Set CSV EOF Tab( 0 ),
<<Set CSV EOF Space( 0 ),
<<Set CSV EOF Spaces( 0 ),
<<Set CSV EOF Other( "" ),
<<Set CSV EOL CRLF( 1 ),
<<Set CSV EOL CR( 1 ),
<<Set CSV EOL LF( 1 ),
<<Set CSV EOL Semicolon( 0 ),
<<Set CSV EOL Other( "" ),
<<Set CSV Quote( "\!"" ),
<<Set CSV Escape( "" )
) << Import Data