- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Open files using contains ()
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
...
)
);
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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 );
)
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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 );
)
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Open files using contains ()
Hi, it is working, however, is it possible to have multiple conditions on my contain() function?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.