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
Jiaxiang
Level I

How do I get the file names with a specific suffix from a folder?

I am trying to import some data from a folder, it contains different type of files, and I just want the file with *.s2p suffix, how can I  get all the filename with  .s2p  suffix?  I use files in directory function, but it can only get all the filename.

fileNames = Files In Directory( directory );    
2 REPLIES 2
jthi
Super User

Re: How do I get the file names with a specific suffix from a folder?

You could try using Multiple File Import found from File / Import Multiple Files...

jthi_0-1640934626650.png

 

or loop over the list you have while filtering out non-wanted results.

Names Default To Here(1);

fileNames = {"test0.s2p", "test.jmp", "test1.jsl", "test2.s2p"};
suffix_of_interest = ".s2p";

//JMP16
files_of_interest = Filter Each({val}, fileNames, Ends With(val, suffix_of_interest));
show(files_of_interest);

//earlier
files_of_interest2 = {};
For(i = 1, i <= N Items(fileNames), i++,
	val = fileNames[i];
	If(Ends With(val, suffix_of_interest),
		Insert Into(files_of_interest2, val);
	);
);
show(files_of_interest2);

 

-Jarmo
Craige_Hales
Super User

Re: How do I get the file names with a specific suffix from a folder?

Nice! Now I need to go read about Filter Each:

Filter Each for JMP 16 in Help->Scripting IndexFilter Each for JMP 16 in Help->Scripting Index

The scripting index has three examples; the Associative Array example is in the picture. I like  @jthi  example because it hints that the expression for selecting items can be more complicated.

 

Craige