cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
terapin
Level VI

Open JMP file Using Variable and Wildcard

After prompting the user to select a text file, the file is opened and a variable is created based on the site name contained in this text data filename as follows


dt.rawdata = Open (

     Pick File( ......

     )

);

// Create string that is filename

dtname = dt.rawdata << Get Name;

// Create variable called siteid that removes just the site name from the filename

If( Word( 1, dtname, "_" ) == "UC",

  siteid = "UC_" || Word( 2, dtname, "_" ),

  siteid = Word( 1, dtname, "_" )

);

What I'm struggling with now is how to open a JMP data file whose name contains the siteid just determined.  There are about 40 .xls and .jmp data files in a directory and I'm trying to open the only JMP file that contains siteid in the filename as follows

where ? is a wildcard for the text string that follows LTEM Data.  The filenames follow the format siteid LTEM Data, yyyy - YTD.jmp where yyyy refers to starting year and varies depending on the site id.

dt.metplots = Open(

  "$dir_metplots/" || siteid || " LTEM Data?" || ".jmp"

);

Is there a wildcard that can be used for this or is there some other clever way to accomplish this?  Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Open JMP file Using Variable and Wildcard

I don't think wildcards can be used here.

Maybe this approach works for you (first commands just copied from above):

dt.rawdata = Open( Pick File());

// Create string that is filename

dtname = dt.rawdata << Get Name;

// Create variable called siteid that removes just the site name from the filename

If( Word( 1, dtname, "_" ) == "UC",

  siteid = "UC_" || Word( 2, dtname, "_" ),

  siteid = Word( 1, dtname, "_" )

);

// Create list of files in directory

path = "$dir_metplots/";

files = Files In Directory( path );

n = N Items( files );

// Get name of the file that starts with current siteid

For( i = 1, i <= n, i++,

  If( Starts With( files[i], siteid ),

  filename = files[i];

  Break()

  )

);

// Open file

dt.metplots = Open( path || filename );

View solution in original post

2 REPLIES 2
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Open JMP file Using Variable and Wildcard

I don't think wildcards can be used here.

Maybe this approach works for you (first commands just copied from above):

dt.rawdata = Open( Pick File());

// Create string that is filename

dtname = dt.rawdata << Get Name;

// Create variable called siteid that removes just the site name from the filename

If( Word( 1, dtname, "_" ) == "UC",

  siteid = "UC_" || Word( 2, dtname, "_" ),

  siteid = Word( 1, dtname, "_" )

);

// Create list of files in directory

path = "$dir_metplots/";

files = Files In Directory( path );

n = N Items( files );

// Get name of the file that starts with current siteid

For( i = 1, i <= n, i++,

  If( Starts With( files[i], siteid ),

  filename = files[i];

  Break()

  )

);

// Open file

dt.metplots = Open( path || filename );

terapin
Level VI

Re: Open JMP file Using Variable and Wildcard

Thanks MS,

That works great.  I was wondering how with the code provided it managed to grab the correct JMP files even though many other files with the siteid prefix existed.  Turns out it was luck that the correct file I want to open was the first listed with the siteid prefix.  So, to ensure that I opened the JMP file in the event that the first file corresponding to siteid in the list wasn't a JMP file, I added the following Ends With code.  

For( i = 1, i <= n, i++,

  If( AND( Starts With( files, siteid ), Ends With( files, "jmp" ) ),

  filename = files;

  Break();

  )

);

Learned a lot from this little exercise.  Thanks again for your helping out.