cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
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
ian_jmp
Level X

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
ian_jmp
Level X

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

 

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.