cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Get the free JMP Student Edition for qualified students and instructors at degree granting institutions.
Choose Language Hide Translation Bar
View Original Published Thread

Open files using contains ()

UserID16644
Level V

Hi all, 

I am try to create a script that would go through directories to find the input file. However, some file names may have different characters. 

 

For example:

My input in favorite fruit would be: Orange

Existing files from folder would be: Mark_Orange_Mango.jmp, Jane_Apple.jmp, John_Orange.jmp

Files that would open: Mark_Orange_Mango.jmp and John_Orange.jmp

 

How can I open these files using contains() or what function do I need to use? I am using JMP 15

 

Here is the piece of code I am working on:

 

nw = New Window( "Favorite Fruits", << modal(),
	lineupbox(ncol(2), spacing(5),
		
		Text Box( "Name:" ),
		teb1 = Text Edit Box( "", <<set width( 150 ) ),
		
		Text Box( "Age:" ),
		teb2 = Text Edit Box( "", <<set width( 150 ) ),

		Text Box( "Birthday:" ),
		teb3 = Text Edit Box( "", <<set width( 150 ) ),
		
		Text Box( "Favorite Fruit:" ),
		teb4 = Text Edit Box( "", <<set width( 150 ) ),
	),
	Button Box( "OK", 
		name = teb1 << get text ();
		age = teb2 << get text ();
		bday = teb3 << get text ();
		fruit = teb4 << get text ();	
	),
);


/* ----- opening the files ----- */

path = "C:\Users\Desktop" || Char (name) || "\" || Char (bday);

files = Files in Directory (path);

For (j=1, j<= N Items (files), j++,
	If (Contains (fruit[j], ".jmp"), // Open file that contains the input from text box
	...
	)
);
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User


Re: Open files using contains ()

See if this works for you

nw = New Window( "Favorite Fruits",
	<<modal(),
	Lineup Box( N Col( 2 ), spacing( 5 ), 
		
		Text Box( "Name:" ),
		teb1 = Text Edit Box( "", <<set width( 150 ) ), 
		
		Text Box( "Age:" ),
		teb2 = Text Edit Box( "", <<set width( 150 ) ), 

		Text Box( "Birthday:" ),
		teb3 = Text Edit Box( "", <<set width( 150 ) ), 
		
		Text Box( "Favorite Fruit:" ),
		teb4 = Text Edit Box( "", <<set width( 150 ) ),

	),
	Button Box( "OK",
		name = teb1 << get text();
		age = teb2 << get text();
		bday = teb3 << get text();
		fruit = teb4 << get text();
	),

);

/* ----- opening the files ----- */

path = "C:\Users\Desktop" || Char( name ) || "\" || Char( bday );

files = Files In Directory();

For( i = N Items( files ), i >= 1, i--,
	If( Word( -1, files[i], "." ) != "jmp",
		Remove From( files, i, 1 )
	)
);

If( N Items( Files ) > 0,
	tableList = {};
	For( j = 1, j <= N Items( files ), j++,
		If( Contains( files[j], fruit ) > 0, // Open file that contains the input from text box
			dd = Open( path || "/" || files[j] );
			Insert Into( tableList, dd );
		)
	);
);
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User


Re: Open files using contains ()

See if this works for you

nw = New Window( "Favorite Fruits",
	<<modal(),
	Lineup Box( N Col( 2 ), spacing( 5 ), 
		
		Text Box( "Name:" ),
		teb1 = Text Edit Box( "", <<set width( 150 ) ), 
		
		Text Box( "Age:" ),
		teb2 = Text Edit Box( "", <<set width( 150 ) ), 

		Text Box( "Birthday:" ),
		teb3 = Text Edit Box( "", <<set width( 150 ) ), 
		
		Text Box( "Favorite Fruit:" ),
		teb4 = Text Edit Box( "", <<set width( 150 ) ),

	),
	Button Box( "OK",
		name = teb1 << get text();
		age = teb2 << get text();
		bday = teb3 << get text();
		fruit = teb4 << get text();
	),

);

/* ----- opening the files ----- */

path = "C:\Users\Desktop" || Char( name ) || "\" || Char( bday );

files = Files In Directory();

For( i = N Items( files ), i >= 1, i--,
	If( Word( -1, files[i], "." ) != "jmp",
		Remove From( files, i, 1 )
	)
);

If( N Items( Files ) > 0,
	tableList = {};
	For( j = 1, j <= N Items( files ), j++,
		If( Contains( files[j], fruit ) > 0, // Open file that contains the input from text box
			dd = Open( path || "/" || files[j] );
			Insert Into( tableList, dd );
		)
	);
);
Jim
UserID16644
Level V


Re: Open files using contains ()

Hi, it is working, however, is it possible to have multiple conditions on my contain() function?

txnelson
Super User


Re: Open files using contains ()

It can be as complex as you want it to be

If(
(Contains( files[j], fruit ) & Contains( files[j], "Good Luck" )) |
Contains( files[j], "Special" ),
dd = Open( path || "/" || files[j] )
)

I strongly suggest you take some time to read the Scripting Guide.  It will make your journey into scripting far more pleasent. 

Jim