- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
File Saving and Overwriting
I have a JSL scripts that opens and closes serval sheets. While they're open, it merges the documents into a single file, then saves the file into a local folder. The script currently overwrites the existing file in the local folder. Is there a script that would populate a new file in a subfolder (ideally, distinguished by tagging the a timestamp of creation onto the title "Merged") every time the script is run, instead of overwriting the current one? Or better yet, it's ok if the current one is over written, but a copy of it gets saved into a subfolder every time the script is run? Sort of like a back log I can look at but others can only see the "live" version
@txnelson, I've seen you help here with something similar: Save new graph instead of overwriting the already saved ones
Maybe it's a variation of this?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: File Saving and Overwriting
Both options are possible with little bit of scripting. You can easily get "timestamp" by using Today().
Here is fairly simple example how you could do just saving with timestamp:
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
table_name = dt << get name;
timestamp = Today();
save_path = Eval Insert("$temp\^timestamp^_^table_name^.jmp");
dt << Save(save_path);
Open("$temp");
With saving to other folder, you could just do two saves with different paths and filenames or copy the file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: File Saving and Overwriting
Today() does generate timestamp, but it is in JMP date time value Using dates, times, datetimes and durations in JMP.
If you use AsDate() it will most likely have some characters which are not allowed in filenames. What type of format do you want? You can build it from the datetime Today() gives you, check out Scripting Index and Date Time part:
From there you can find functions like Year(), Month(), Day(), Hour(), Minute() and Second() with these (combined with Char() or Eval Insert() you can build most robust version of the timestamp you want.
Edit:
This is a bit of long code, but it should be fairly robust and basically give you YYYYMMDD_hhmmss formatted string
Names Default To Here(1);
cur_time = Today();
yyyy = char(Year(cur_time));
//add spanning
mm = char(Month(cur_time));
mm = Substr("00", 1, 2 - Length(mm)) || mm;
dd = char(Day(cur_time));
dd = Substr("00", 1, 2 - Length(dd)) || dd;
hh = char(Hour(cur_time));
hh = Substr("00", 1, 2 - Length(hh)) || hh;
min = char(Minute(cur_time));
min = Substr("00", 1, 2 - Length(min)) || min;
ss = char(Second(cur_time));
ss = Substr("00", 1, 2 - Length(ss)) || ss;
timestamp_str = yyyy || mm || dd ||"_"|| hh || min || ss;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: File Saving and Overwriting
Both options are possible with little bit of scripting. You can easily get "timestamp" by using Today().
Here is fairly simple example how you could do just saving with timestamp:
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
table_name = dt << get name;
timestamp = Today();
save_path = Eval Insert("$temp\^timestamp^_^table_name^.jmp");
dt << Save(save_path);
Open("$temp");
With saving to other folder, you could just do two saves with different paths and filenames or copy the file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: File Saving and Overwriting
Thanks jthi!
The script works great, except the timestamp is populating values like "3727386650" before the table name. I tried making timestamp:
timestamp = As Date( Today() );
To populate the date and time, but the script was unable to save the file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: File Saving and Overwriting
Today() does generate timestamp, but it is in JMP date time value Using dates, times, datetimes and durations in JMP.
If you use AsDate() it will most likely have some characters which are not allowed in filenames. What type of format do you want? You can build it from the datetime Today() gives you, check out Scripting Index and Date Time part:
From there you can find functions like Year(), Month(), Day(), Hour(), Minute() and Second() with these (combined with Char() or Eval Insert() you can build most robust version of the timestamp you want.
Edit:
This is a bit of long code, but it should be fairly robust and basically give you YYYYMMDD_hhmmss formatted string
Names Default To Here(1);
cur_time = Today();
yyyy = char(Year(cur_time));
//add spanning
mm = char(Month(cur_time));
mm = Substr("00", 1, 2 - Length(mm)) || mm;
dd = char(Day(cur_time));
dd = Substr("00", 1, 2 - Length(dd)) || dd;
hh = char(Hour(cur_time));
hh = Substr("00", 1, 2 - Length(hh)) || hh;
min = char(Minute(cur_time));
min = Substr("00", 1, 2 - Length(min)) || min;
ss = char(Second(cur_time));
ss = Substr("00", 1, 2 - Length(ss)) || ss;
timestamp_str = yyyy || mm || dd ||"_"|| hh || min || ss;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: File Saving and Overwriting
Worked like a charm! Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: File Saving and Overwriting
You can use
rc = Copy File( from, to );
to copy the file. Look in the Script Editor for the details and a good example on the Copy File
Once you copy the file to your desired sub directory you can simply use
data table("table name") << Save ("file path" );
to save the new table. In the file path, you give the the path and the complete file name, including the .jmp extension.