Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
AY
AY
Level II

How to get path and save as .jmp

Hi. I am still new with JMP. I am greatly appreciate if anyone could help me with this problem.

 

I want to open .csv file. Then get the path of that .csv file and then save that .csv file as .jmp

I use:

files = Open(); // from here i can open my .csv file

files << get path; // tried to get the path using this code but this doesnt give me the path 

 

Anyone can please help me? Thank you so much

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
ian_jmp
Staff

Re: How to get path and save as .jmp

Probably to be expected, but '<<getPath' doesn't necessarily return the correct path to the file until the table has actually been saved. But you can get the path of the CSV file from the 'Source' script in the table (see below).

But I have the sense that you want to do this many times, in which case the code below shuld get you started.

If you are new to JMP, use 'Help > Scripting Index' to understand how each line works. If you really do want to do this for multiple files, you can delete the lines ending in '//'.

NamesDefaultToHere(1);

// Pick a directory
dir = pickDirectory("Pick a directory containing .CSV files:", "$DESKTOP");

// Get the .CSV files it contains
fList = filesInDirectory(dir);
for(f=NItems(fList), f>=1, f--,
	ext = ".CSV";
	if(!endsWith(uppercase(fList[f]), ext), removeFrom(fList, f));
	);

// Loop over the .CSV files and save each one as a .JMP file to the same location
for (f=1, f<=NItems(fList), f++,
	dt = Open(dir||"/"||fList[f], Invisible);
	Print("Path to (unsaved!) JMP table is: "||(dt << getPath));			//
	sourceScript = dt << getScript("Source");								//
	Print("Path to source file is: "||Arg(sourceScript, 1));				//
	Close(dt, Save(dir||"/"||Word(1, fList[f], ".")||".jmp"));
	Print("Saved "||dir||"/"||Word(1, fList[f], ".")||".jmp ... ");
	);

 

View solution in original post

2 REPLIES 2
Highlighted
ian_jmp
Staff

Re: How to get path and save as .jmp

Probably to be expected, but '<<getPath' doesn't necessarily return the correct path to the file until the table has actually been saved. But you can get the path of the CSV file from the 'Source' script in the table (see below).

But I have the sense that you want to do this many times, in which case the code below shuld get you started.

If you are new to JMP, use 'Help > Scripting Index' to understand how each line works. If you really do want to do this for multiple files, you can delete the lines ending in '//'.

NamesDefaultToHere(1);

// Pick a directory
dir = pickDirectory("Pick a directory containing .CSV files:", "$DESKTOP");

// Get the .CSV files it contains
fList = filesInDirectory(dir);
for(f=NItems(fList), f>=1, f--,
	ext = ".CSV";
	if(!endsWith(uppercase(fList[f]), ext), removeFrom(fList, f));
	);

// Loop over the .CSV files and save each one as a .JMP file to the same location
for (f=1, f<=NItems(fList), f++,
	dt = Open(dir||"/"||fList[f], Invisible);
	Print("Path to (unsaved!) JMP table is: "||(dt << getPath));			//
	sourceScript = dt << getScript("Source");								//
	Print("Path to source file is: "||Arg(sourceScript, 1));				//
	Close(dt, Save(dir||"/"||Word(1, fList[f], ".")||".jmp"));
	Print("Saved "||dir||"/"||Word(1, fList[f], ".")||".jmp ... ");
	);

 

View solution in original post

Highlighted
AY
AY
Level II

Re: How to get path and save as .jmp

Thanks a lot for this solution. Really gave me some ideas on how should i write my script. Thanks again.

Article Labels

    There are no labels assigned to this post.