<?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 Extract and concatenate csv files from folders that have the same structure in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19468#M17748</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a whole bunch of csv files in different folders that have common name and csv file is in the same structure, for instance&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;1st folder&amp;gt;dfgdwgssd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;2nd folder which have common name&amp;gt; commonname&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xxx-commonname.csv&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm thinking to use script to extract and concatenate all csv files. I found an easy way with bash commands ("for" loop together with "find"), could some one give me a hand? Thank you so much!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 10 Jul 2016 04:06:12 GMT</pubDate>
    <dc:creator>jyw</dc:creator>
    <dc:date>2016-07-10T04:06:12Z</dc:date>
    <item>
      <title>Extract and concatenate csv files from folders that have the same structure</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19468#M17748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a whole bunch of csv files in different folders that have common name and csv file is in the same structure, for instance&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;1st folder&amp;gt;dfgdwgssd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;2nd folder which have common name&amp;gt; commonname&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xxx-commonname.csv&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm thinking to use script to extract and concatenate all csv files. I found an easy way with bash commands ("for" loop together with "find"), could some one give me a hand? Thank you so much!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Jul 2016 04:06:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19468#M17748</guid>
      <dc:creator>jyw</dc:creator>
      <dc:date>2016-07-10T04:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: Extract and concatenate csv files from folders that have the same structure</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19469#M17749</link>
      <description>&lt;P&gt;Here is a script that should give you a good start:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
// Setup an empty table to start to concatenate other tables to
dtbase = New Table( "Base Table" );
// Have the user select the starting folder
dirpath = Pick Directory( "Pick the Top Level Directory" );
// Get all of the files in all of the folders that are under the picked folder
TheFileList = Files In Directory( dirpath, "recursive" );
 
// Go through all of the files and read in append those that meet your
// requirement.  You will need to amend the IF statement to meet your criteria
For( i = 1, i &amp;lt;= N Items( TheFileList ), i++,
       If( Uppercase( Word( -1, TheFileList[i], "." ) ) == "CSV" &amp;amp; Is File( dirpath || TheFileList[i] ) == 1,
              dt = Open( dirpath || TheFileList[i] );
              dtbase = dtbase &amp;lt;&amp;lt; concatenate( dt, append to first table( 1 ) );
              Close( dt, nosave );
       );
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 13:49:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19469#M17749</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-05-18T13:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Extract and concatenate csv files from folders that have the same structure</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19470#M17750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I got it working, but it listed all CSV files, I'm trying to find the way to sort out or specify the 2nd layer. could you please give a bit more tips? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jul 2016 05:43:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19470#M17750</guid>
      <dc:creator>jyw</dc:creator>
      <dc:date>2016-07-11T05:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extract and concatenate csv files from folders that have the same structure</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19471#M17751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you know ahead of time what the "common name" is?&amp;nbsp; Or do you need to have the script figure that out?&amp;nbsp; And in that case, will there be more than one possible common name found in the folder?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jul 2016 10:10:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19471#M17751</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2016-07-11T10:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: Extract and concatenate csv files from folders that have the same structure</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19472#M17752</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes, I do know what the "common name" is for both 2nd layer and the csv files. Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Jul 2016 16:22:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19472#M17752</guid>
      <dc:creator>jyw</dc:creator>
      <dc:date>2016-07-11T16:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extract and concatenate csv files from folders that have the same structure</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19473#M17753</link>
      <description>&lt;P style="margin: 0px; font-size: 12px; line-height: normal; font-family: Courier; color: #032ce4;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
// Setup an empty table to start to concatenate other tables to
dtbase = New Table( "Base Table" );
// Have the user select the starting folder
dirpath = Pick Directory( "Pick the Top Level Directory" );
// Get all of the files in all of the folders that are under the picked folder
TheFileList = Files In Directory( dirpath, "recursive" );
 
// Go through all of the files and read in append those that meet your
// requirement.  You will need to amend the IF statement to meet your criteria
For( i = 1, i &amp;lt;= N Items( TheFileList ), i++,
      If( Uppercase( Word( -1, TheFileList[i], "." ) ) == "CSV" &amp;amp; Is File( dirpath || TheFileList[i] ) == 1,
If( Contains ( TheFileList[i], "&amp;lt;2nd folder common name"),
          If( Contains (TheFileList[i],"&amp;lt;common name of the csvfile&amp;gt;"),
  print(TheFileList[i]);
  dt = Open( dirpath || TheFileList[i] );
  dtbase = dtbase &amp;lt;&amp;lt; concatenate( dt, append to first table( 1 ) );
  Close( dt, nosave );
);
);
        );
 
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P style="margin: 0px; font-size: 12px; line-height: normal; font-family: Courier;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0px; font-size: 12px; line-height: normal; font-family: Courier;"&gt;&lt;SPAN style="color: #011993;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;&lt;SPAN style="color: #011993; font-size: 12px; font-family: Courier;"&gt;add two more lines to get it working, the alignment/indent needs to be adjusted though. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;&lt;SPAN style="color: #011993; font-size: 12px; font-family: Courier;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;&lt;SPAN&gt;&lt;SPAN style="color: #011993; font-size: 12px; font-family: Courier;"&gt;Thank you!&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 13:50:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19473#M17753</guid>
      <dc:creator>jyw</dc:creator>
      <dc:date>2018-05-18T13:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: Extract and concatenate csv files from folders that have the same structure</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19474#M17754</link>
      <description>&lt;P&gt;Hi &lt;A href="https://community.jmp.com/people/jyw" target="_blank"&gt;jyw&lt;/A&gt;​,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition to Jim's suggestion you could try the following generalized approach for selecting the files you want. See below for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal; font-family: Menlo;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;allFiles = FilesInDirectory("$Documents", recursive);
selectedFiles = {};
commonName = "BrownP";
For( i = 1, i&amp;lt;=NItems(allFiles), i++,
If( !IsMissing( Regex(allFiles, EvalInsert(".*&amp;lt;commonName&amp;gt;.*\.csv","&amp;lt;","&amp;gt;" )) ),
      InsertInto(selectedFiles, allFiles);
)
 
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P style="margin: 0px; line-height: normal; font-family: Menlo;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal; font-family: Menlo;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal; font-family: Menlo;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;1. Retrieve all filenames in the My Documents folder and its subfolders. (Replace with your top level folder path).&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;2. Create an empty list to store the filenames you want.&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;3. Define the commonName string.&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;4. Loop through all filenames, selecting only the ones that match the pattern and store in the &lt;EM&gt;​selectedFiles&lt;/EM&gt;​ list. In this example&lt;SPAN style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"&gt; I'm retrieving all the CSV files that contain "BrownP" in the filename. (Replace with your own commonName string).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;So, the full implementation (using Jim's code from the previous post):&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal; font-family: Menlo; color: #032ce4;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
// Setup an empty table to start to concatenate other tables to
dtbase = New Table( "Base Table" );
// Have the user select the starting folder
dirpath = Pick Directory( "Pick the Top Level Directory" );
// Get all of the files in all of the folders that are under the picked folder
TheFileList = Files In Directory( dirpath, "recursive" );
 
// Define common string to search for
commonName = "file";
 
// Go through all of the files and read in append those that meet your
// requirement.  You will need to amend the IF statement to meet your criteria
For( i = 1, i &amp;lt;= N Items( TheFileList ), i++,
If( !Is Missing( Regex( TheFileList, Eval Insert( ".*&amp;lt;commonName&amp;gt;.*\.csv", "&amp;lt;", "&amp;gt;" ) ) ),
dt = Open( dirpath || TheFileList );
dtbase = dtbase &amp;lt;&amp;lt; concatenate( dt, append to first table( 1 ) );
Close( dt, nosave );
)
 
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P style="margin: 0px; line-height: normal; font-family: Menlo;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;Hope this helps!&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;Best,&lt;/P&gt;
&lt;P style="margin: 0px; line-height: normal;"&gt;Phil&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 13:51:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19474#M17754</guid>
      <dc:creator>Phil_Brown</dc:creator>
      <dc:date>2018-05-18T13:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: Extract and concatenate csv files from folders that have the same structure</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19475#M17755</link>
      <description>&lt;P&gt;Hi Phil,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for your tips! I didn't run you script though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was using small amount of folders to try out and realized later on that it took ages with large amount of folder (say &amp;gt;1,300), since JMP will go to 2nd directory and extract *.csv file and so on, very very time-consuming though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In order to improve the efficiency, I thought about using bash to move all csv file to a folder and then concatenate them. A quick check to use bash to do this (extract and concatenate csv files) with &amp;gt;1,300 folders took me 3 seconds with a concatenated csv file of 13MB, 3 seconds!!! I will need to look into the possibility to run bash command inside JSL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;btw, &lt;STRONG style="font-size: 10pt; margin: 0px; padding: 0px; border: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; vertical-align: baseline; color: #555555;"&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( dirpath || TheFileList,invisible );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG style="font-size: 10pt; margin: 0px; padding: 0px; border: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; vertical-align: baseline; color: #555555;"&gt;&lt;SPAN style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: Consolas; vertical-align: baseline; color: navy;"&gt; will not pop up the data table during processing&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you again!&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 13:52:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19475#M17755</guid>
      <dc:creator>jyw</dc:creator>
      <dc:date>2018-05-18T13:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: Extract and concatenate csv files from folders that have the same structure</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19476#M17756</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure my pleasure! I was trying to point out that you could still use JMP to retrieve the entire list of files and then use REGEX to search the for the filenames that contain&amp;nbsp; &amp;lt;commonName&amp;gt; . Indeed I can imagine with 1300+ folders it could take some time. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A couple pointers on speed:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10pt;"&gt; - Printing to the log does slow things down.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Also, I would open all the files first before concatenating and closing each one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*If you're using a Mac you can launch a shell script from JMP. On Windows, unless you're using Cygwin or something like that, Powershell is a good option to write utility procedures that can be called from JMP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Phil&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jul 2016 13:34:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19476#M17756</guid>
      <dc:creator>Phil_Brown</dc:creator>
      <dc:date>2016-07-12T13:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: Extract and concatenate csv files from folders that have the same structure</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19477#M17757</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you again, Phil! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm using Mac, and just searched on Google, found little information about running shell from JMP, do you have some examples?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jul 2016 16:43:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-and-concatenate-csv-files-from-folders-that-have-the/m-p/19477#M17757</guid>
      <dc:creator>jyw</dc:creator>
      <dc:date>2016-07-12T16:43:01Z</dc:date>
    </item>
  </channel>
</rss>

