<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: JSL script to open multiple excel file using wildcard. in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46918#M26734</link>
    <description>&lt;P&gt;If you want to open every file in that directory&amp;nbsp;(you know they are all xls files) then you are done and do not need to worry about regex.&amp;nbsp; If you only want to open files that&amp;nbsp;start with 'my file' and end in '.xls' then you could make sure the file matches your criteria by adding an if statement inside your for loop, similar to this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Untested Code*&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Read all the file names
files = Files In Directory( "C:\Users\MyUserName\Documents\My Data\" );

X = N Items( files );

Y = "C:\Users\MyUserName\Documents\My Data\";

dt = New Table( "My data file" );

For( i = 1, i &amp;lt; X, i++, 

	if( !is missing( regex( files[i], "my file.*\.xls", "\0" , IGNORECASE ) ),


		//open jmp files for each xls files.

		dt1 = Open(

			Y || files[i], 

			Worksheets( "my xls worksheet" ), 

			Use for all sheets( 0 ), 

			Concatenate Worksheets( 0 ), 

			Create Concatenation Column( 0 ), 

	 

			Worksheet Settings(

				1, 
				Has Column Headers( 0 ), 
				Number of Rows in Headers( 1 ), 
				Headers Start on Row( 1 ), 
				Data Starts on Row( 1 ), 
				Data Starts on Column( 1 ), 
				Data Ends on Row( 0 ), 
				Data Ends on Column( 0 ), 
				Replicated Spanned Rows( 1 ), 
				Suppress Hidden Rows( 1 ), 
				Suppress Hidden Columns( 1 ), 
				Suppress Empty Columns( 1 ), 
				Treat as Hierarchy( 0 )
			)

		);

		dt1 &amp;lt;&amp;lt; Set Name( files[i] );

	 

		//I concatenated all the files in one jmp file and close it each time.
		dt &amp;lt;&amp;lt; Concatenate( Data Table( dt1 ), "Append to first table" );

		Close( dt1 );
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 08 Nov 2017 19:34:28 GMT</pubDate>
    <dc:creator>ih</dc:creator>
    <dc:date>2017-11-08T19:34:28Z</dc:date>
    <item>
      <title>JSL script to open multiple excel file using wildcard.</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46876#M26703</link>
      <description>&lt;P&gt;Hi, Could anyone help me to code JSL to open multiple excel files using wildcard?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 22:09:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46876#M26703</guid>
      <dc:creator>Trana</dc:creator>
      <dc:date>2017-11-07T22:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script to open multiple excel file using wildcard.</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46880#M26707</link>
      <description>&lt;P&gt;Here is one way which might get you started.&amp;nbsp; Unless other users will enter the search phrase I recommend specifying the regex yourself. &lt;A href="http://www.regexr.com" target="_self"&gt;Regexr &lt;/A&gt;is a great resource.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//list all files in directory
files = Files in Directory( Pick Directory() );

//a string with wildcards, * for any string and ? for exactly one character
str = "My?Files*.xls*";

//Replace windcards with regex character classes.  Note that this does 
//not protect against all strings a user might enter
rgx = Substitute( str, ".", "\.", "*", ".*", "?", "." );

//Or just specify the regex yourself
rgx = "My Files.*\.xlsx?";

//Check each file, if it matches then open it
if(	N items( files ) &amp;gt; 0, 
	for( i = 1, i &amp;lt;= N items( files ), i++,
		if( !is missing( regex( files[i], rgx, "\0" , IGNORECASE ) ),
			//Open script goes here
			Show( files[i] );
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 02:57:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46880#M26707</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2017-11-08T02:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script to open multiple excel file using wildcard.</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46917#M26733</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for taking your time to give me the solution. Your solution is worked. I used the following script:&lt;/P&gt;
&lt;P&gt;However, I am not sure how can I use regex here and how using regex will be benificial.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My script:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Read all the file names
files = Files In Directory( "C:\Users\MyUserName\Documents\My Data\" );
X = N Items( files );
Y = "C:\Users\MyUserName\Documents\My Data\";
dt = New Table( "My data file");
For( i = 1, i &amp;lt; X, i++,
//open jmp files for each xls files.
dt1 = Open(
Y || files[i],
Worksheets( "my xls worksheet" ),
Use for all sheets( 0 ),
Concatenate Worksheets( 0 ),
Create Concatenation Column( 0 ),
 
Worksheet Settings(
1,
Has Column Headers( 0 ),
Number of Rows in Headers( 1 ),
Headers Start on Row( 1 ),
Data Starts on Row( 1 ),
Data Starts on Column( 1 ),
Data Ends on Row( 0 ),
Data Ends on Column( 0 ),
Replicated Spanned Rows( 1 ),
Suppress Hidden Rows( 1 ),
Suppress Hidden Columns( 1 ),
Suppress Empty Columns( 1 ),
Treat as Hierarchy( 0 )
 
)
);
dt1 &amp;lt;&amp;lt; Set Name( files[i] );
 
 
//I concatenated all the files in one jmp file and close it each time.
dt &amp;lt;&amp;lt; Concatenate( Data Table( dt1 ), "Append to first table" );
Close( dt1 );
 
　
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 20:10:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46917#M26733</guid>
      <dc:creator>Trana</dc:creator>
      <dc:date>2017-11-08T20:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script to open multiple excel file using wildcard.</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46918#M26734</link>
      <description>&lt;P&gt;If you want to open every file in that directory&amp;nbsp;(you know they are all xls files) then you are done and do not need to worry about regex.&amp;nbsp; If you only want to open files that&amp;nbsp;start with 'my file' and end in '.xls' then you could make sure the file matches your criteria by adding an if statement inside your for loop, similar to this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Untested Code*&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Read all the file names
files = Files In Directory( "C:\Users\MyUserName\Documents\My Data\" );

X = N Items( files );

Y = "C:\Users\MyUserName\Documents\My Data\";

dt = New Table( "My data file" );

For( i = 1, i &amp;lt; X, i++, 

	if( !is missing( regex( files[i], "my file.*\.xls", "\0" , IGNORECASE ) ),


		//open jmp files for each xls files.

		dt1 = Open(

			Y || files[i], 

			Worksheets( "my xls worksheet" ), 

			Use for all sheets( 0 ), 

			Concatenate Worksheets( 0 ), 

			Create Concatenation Column( 0 ), 

	 

			Worksheet Settings(

				1, 
				Has Column Headers( 0 ), 
				Number of Rows in Headers( 1 ), 
				Headers Start on Row( 1 ), 
				Data Starts on Row( 1 ), 
				Data Starts on Column( 1 ), 
				Data Ends on Row( 0 ), 
				Data Ends on Column( 0 ), 
				Replicated Spanned Rows( 1 ), 
				Suppress Hidden Rows( 1 ), 
				Suppress Hidden Columns( 1 ), 
				Suppress Empty Columns( 1 ), 
				Treat as Hierarchy( 0 )
			)

		);

		dt1 &amp;lt;&amp;lt; Set Name( files[i] );

	 

		//I concatenated all the files in one jmp file and close it each time.
		dt &amp;lt;&amp;lt; Concatenate( Data Table( dt1 ), "Append to first table" );

		Close( dt1 );
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Nov 2017 19:34:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46918#M26734</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2017-11-08T19:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script to open multiple excel file using wildcard.</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46923#M26738</link>
      <description>&lt;P&gt;Your original question requested the capability to use a Wildcard when selecting the file names to be read into JMP.&amp;nbsp; RegEx() has a syntax that allows for Wildcards.&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/6657"&gt;@ih&lt;/a&gt;&amp;nbsp;illustrated how you can structure a RegEx() function to return file names meeting a structure using Wildcards.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the question needs to go back to you to qualify what your thinging was when you specified "using wildcard"?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 19:54:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46923#M26738</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2017-11-08T19:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script to open multiple excel file using wildcard.</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46927#M26742</link>
      <description>Thanks for the response. I thought I would use wild card to select all the files (something like *.*). Seems regex is great to select specific files based on some criteria. Seems for my need now, I can just use the for loop to open all files. I am sure I will need regex later for more flexibility.</description>
      <pubDate>Wed, 08 Nov 2017 20:13:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46927#M26742</guid>
      <dc:creator>Trana</dc:creator>
      <dc:date>2017-11-08T20:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script to open multiple excel file using wildcard.</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46929#M26743</link>
      <description>&lt;P&gt;In that case you might also consider using Pick File&amp;nbsp;function with the "multiple" keyword. From the scripting index:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
Files =
Pick File(
	"Select JMP File",
	"$SAMPLE_DATA",
	{"JMP Files|jmp;jsl;jrn", "All Files|*"},
	1,
	0,
	"",
	"multiple"
);
For( i = 1, i &amp;lt;= N Items( Files ), i++,
	Try( Open( Files[i] ) )
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Nov 2017 20:19:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-to-open-multiple-excel-file-using-wildcard/m-p/46929#M26743</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2017-11-08T20:19:56Z</dc:date>
    </item>
  </channel>
</rss>

