<?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: How to save text file open setting into script in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-save-text-file-open-setting-into-script/m-p/381112#M63165</link>
    <description>&lt;P&gt;Thanks Jim for showing Open Multiple files. It seems to be very powerful. Strangely, I have never used it – probably because of old habit of scripting tasks like this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all files have exactly the same number of rows, the below script should give the same final table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
path = "path to directory of text files";
files = Files In Directory( path );

open_expr = Expr(
	dt = Open(
		path || Expr( files[i] ),
		Import Settings(
			End Of Line( CRLF, CR, LF ),
			End Of Field( Spaces, CSV( 0 ) ),
			Data Starts( 7 ),
			Lines To Read( "All" )
		),
		private
	)
);

M = []; //Matrix to hold data from multiple files
L = {}; // List of imported file names

For( i = 1, i &amp;lt;= N Items( files ), i++,
	If( Ends With( files[i], ".txt" ),
		Eval( Eval Expr( open_expr ) );
		Insert Into( L, files[i] );
		M ||= dt[0, 5]; // Add column 4 (5 becaue of fronting spaces in files)
		Close( dt, no save );
	)
);
// Make into table
dt = As Table( M, &amp;lt;&amp;lt;Column names( L ) );


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Apr 2021 23:38:20 GMT</pubDate>
    <dc:creator>ms</dc:creator>
    <dc:date>2021-04-29T23:38:20Z</dc:date>
    <item>
      <title>How to save text file open setting into script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-save-text-file-open-setting-into-script/m-p/380924#M63141</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem:&lt;/P&gt;&lt;P&gt;I have numerous .txt files. I only care about the data in column 4, starting with row 7 to infinity. I would like to extract all of the data from column 4 from the numerous .txt files and concatenate them into a single table. What is the best way to do this? Ideally, I would like to create a script to execute this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Along the same vein, when I use the File - open method to open the .txt files with Data (using preview), I can properly format my column 4 data, BUT I can't figure out how to find or save these 'open' setting. I would like to save to the script so I can open the other .txt files with the same settings.&lt;/P&gt;&lt;P&gt;How do I do this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've attached one of my sample .txt files for reference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:29:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-save-text-file-open-setting-into-script/m-p/380924#M63141</guid>
      <dc:creator>Kathorvath</dc:creator>
      <dc:date>2023-06-10T23:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to save text file open setting into script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-save-text-file-open-setting-into-script/m-p/380970#M63148</link>
      <description>&lt;P&gt;I believe the route to take is to use Import Multiple Files&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;File=&amp;gt;Import Multiple Files&lt;/P&gt;
&lt;P&gt;You will read in all files in a folder, and concatenate them(if you want).&amp;nbsp; Then all you will have to do, is to delete the columns you don't want.&lt;/P&gt;
&lt;P&gt;Also, after running the whole folder, or maybe just a few files for a test case, you can go to the Source entry in the data table's upper left panel and right click on it and select Edit, and you will get all of the JSL required to run from a script.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 18:27:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-save-text-file-open-setting-into-script/m-p/380970#M63148</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-04-29T18:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to save text file open setting into script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-save-text-file-open-setting-into-script/m-p/381055#M63159</link>
      <description>&lt;P&gt;Sorry, I did not describe my goal clearly enough. The suggestion does not give me what I need. I've also realized I will need to use the join command not the concatenate command.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 39 .txt files. I only want the data from the 4th column of each .txt file. I want to extract that data and add it to a new table such that I have 39 separate columns (one for each 4th column in all 39 .txt files).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 20:45:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-save-text-file-open-setting-into-script/m-p/381055#M63159</guid>
      <dc:creator>Kathorvath</dc:creator>
      <dc:date>2021-04-29T20:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to save text file open setting into script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-save-text-file-open-setting-into-script/m-p/381081#M63160</link>
      <description>&lt;P&gt;For example purposes, I made 4 copies of your example file, and placed them all into a folder under my Discussion Group folder&lt;/P&gt;
&lt;PRE&gt;Documents\Discussion Group\textfile&lt;/PRE&gt;
&lt;P&gt;I then went to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;File=&amp;gt;Import Multiple File&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="fi1.PNG" style="width: 682px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32433i212F8D5B1CAA7028/image-size/large?v=v2&amp;amp;px=999" role="button" title="fi1.PNG" alt="fi1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I selected the check box for "Add file name column"&lt;/P&gt;
&lt;P&gt;I then clicked on "Settings"&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="fi2.PNG" style="width: 459px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32435iC6182ED0A6A1CFFB/image-size/large?v=v2&amp;amp;px=999" role="button" title="fi2.PNG" alt="fi2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I unchecked "Has Headers"&lt;/P&gt;
&lt;P&gt;I changed the "First Data Line" to 7&lt;/P&gt;
&lt;P&gt;I unchecked in the End Of Field box, "Comma" and checked "Spaces"&lt;/P&gt;
&lt;P&gt;Clicked on OK&lt;/P&gt;
&lt;P&gt;Clicked on Import&lt;/P&gt;
&lt;P&gt;The data table opened with Col1-Col6 columns plus the FileName columns&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="fi3.PNG" style="width: 714px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32436iF4A1FE16C5EC7272/image-size/large?v=v2&amp;amp;px=999" role="button" title="fi3.PNG" alt="fi3.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The only columns that are wanted are columns Col5 and File Name so delete all others&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="fi4.PNG" style="width: 355px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32437i4B69CC5CEAB2FF74/image-size/large?v=v2&amp;amp;px=999" role="button" title="fi4.PNG" alt="fi4.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Now all that has to be done, is to separate the data from the 4 input files into columns&lt;/P&gt;
&lt;P&gt;Go to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Tables=&amp;gt;Split&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="fi5.PNG" style="width: 537px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32451i94AD12C516C7F5E8/image-size/large?v=v2&amp;amp;px=999" role="button" title="fi5.PNG" alt="fi5.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Select File Name as the "Split By" column&lt;/P&gt;
&lt;P&gt;Select Col 5 as the "Split Columns" column&lt;/P&gt;
&lt;P&gt;Click on OK&lt;/P&gt;
&lt;P&gt;The new table will have one column for each of the input files&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="fi6.PNG" style="width: 612px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32452i5AEA3658866C3260/image-size/large?v=v2&amp;amp;px=999" role="button" title="fi6.PNG" alt="fi6.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;This should be the final form of the table you need.&amp;nbsp; You can rename the columns to whatever you want.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 21:22:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-save-text-file-open-setting-into-script/m-p/381081#M63160</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-04-29T21:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to save text file open setting into script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-save-text-file-open-setting-into-script/m-p/381112#M63165</link>
      <description>&lt;P&gt;Thanks Jim for showing Open Multiple files. It seems to be very powerful. Strangely, I have never used it – probably because of old habit of scripting tasks like this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all files have exactly the same number of rows, the below script should give the same final table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
path = "path to directory of text files";
files = Files In Directory( path );

open_expr = Expr(
	dt = Open(
		path || Expr( files[i] ),
		Import Settings(
			End Of Line( CRLF, CR, LF ),
			End Of Field( Spaces, CSV( 0 ) ),
			Data Starts( 7 ),
			Lines To Read( "All" )
		),
		private
	)
);

M = []; //Matrix to hold data from multiple files
L = {}; // List of imported file names

For( i = 1, i &amp;lt;= N Items( files ), i++,
	If( Ends With( files[i], ".txt" ),
		Eval( Eval Expr( open_expr ) );
		Insert Into( L, files[i] );
		M ||= dt[0, 5]; // Add column 4 (5 becaue of fronting spaces in files)
		Close( dt, no save );
	)
);
// Make into table
dt = As Table( M, &amp;lt;&amp;lt;Column names( L ) );


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 23:38:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-save-text-file-open-setting-into-script/m-p/381112#M63165</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2021-04-29T23:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to save text file open setting into script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-save-text-file-open-setting-into-script/m-p/381144#M63168</link>
      <description>&lt;P&gt;Thank you both for the suggestions! I think the scripting option was a little bit more like what I was hoping to do and worked like a charm! I'll have to practice with importing multiple files too.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Apr 2021 02:42:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-save-text-file-open-setting-into-script/m-p/381144#M63168</guid>
      <dc:creator>Kathorvath</dc:creator>
      <dc:date>2021-04-30T02:42:32Z</dc:date>
    </item>
  </channel>
</rss>

