<?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: read and save a txt file from a subdirectory of a ZIP file in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/read-and-save-a-txt-file-from-a-subdirectory-of-a-ZIP-file/m-p/587014#M79253</link>
    <description>&lt;P&gt;The thing to know about zip files: they do not actually have a nested hierarchical directory structure. A zip file's directory is just a simple list of character string names. Those names might contain / or \ characters, and some zip file viewers might try to represent that as a hierarchical nest. So, the zip file member that has a name that contains &lt;EM&gt;mytextfile&lt;/EM&gt; also contains / characters in the name, and when this path is constructed&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;save text file(path1  ||  lst[k]  ||  "_"  ||  dirlist[l]  , text);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;dirlist contains "test/test/mytextfile.txt" and the resulting pathname from the concatenation probably does not exist on your computer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The word() or words() functions might be useful for separating the parts of the path.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jan 2023 15:23:12 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2023-01-05T15:23:12Z</dc:date>
    <item>
      <title>read and save a txt file from a subdirectory of a ZIP file</title>
      <link>https://community.jmp.com/t5/Discussions/read-and-save-a-txt-file-from-a-subdirectory-of-a-ZIP-file/m-p/586819#M79239</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Can someone help. I tried many and still fail.&lt;/P&gt;&lt;P&gt;I tried to loop through a list of zip folder to try to find specific txt file that is under a subdirectory of the zip folder. when I get the filelist&amp;nbsp; in the zip folder, I saw the txt file as subdirector/mytxtfile_123.log. Below is my script, but it fails to download the txt file. there is IO problem where it complains "system cannot find the path specified". I wonder if the flipped of "\" to "/" when I get the filelist. Is there a neat way to get the file in subdirectory or a zip ?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;path == path where all zip folder located;
path1 == path where txt file going to save;
lst = {the list of the zip folders};

for (k=1, k &amp;lt;=N items(lst), k++,
	Try(
    za = open(path||lst[k], zip);
    dirlist = za &amp;lt;&amp;lt; dir;
       
    for (l=1, l&amp;lt;=N Items(dirlist), l++,
		If (Contains(dirlist[l], "mytxtfile_"), 
			text = za &amp;lt;&amp;lt; read(dirlist[l]);
			save text file(path1||lst[k]||"_"||dirlist[l],text);
			
			);
   
		)
		,
    print (lst[k] || "fail to open");
    Throw();
		);
 );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Jun 2023 16:44:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/read-and-save-a-txt-file-from-a-subdirectory-of-a-ZIP-file/m-p/586819#M79239</guid>
      <dc:creator>dadawasozo</dc:creator>
      <dc:date>2023-06-08T16:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: read and save a txt file from a subdirectory of a ZIP file</title>
      <link>https://community.jmp.com/t5/Discussions/read-and-save-a-txt-file-from-a-subdirectory-of-a-ZIP-file/m-p/586841#M79241</link>
      <description>&lt;P&gt;I added an example of a zip folder here as example. Below is the error message&lt;BR /&gt;dirlist = {"test/12.txt", "test/hello.txt", "test/me/", "test/me/testing.txt", "test/test/", "test/test/mytxtfile.txt"};&lt;BR /&gt;IO problem: "mytxtfile" Unable to open in ReadWrite mode.&lt;BR /&gt;The system cannot find the path specified.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2023 03:17:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/read-and-save-a-txt-file-from-a-subdirectory-of-a-ZIP-file/m-p/586841#M79241</guid>
      <dc:creator>dadawasozo</dc:creator>
      <dc:date>2023-01-05T03:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: read and save a txt file from a subdirectory of a ZIP file</title>
      <link>https://community.jmp.com/t5/Discussions/read-and-save-a-txt-file-from-a-subdirectory-of-a-ZIP-file/m-p/586870#M79243</link>
      <description>&lt;P&gt;I didn't (yet) check where your script goes wrong, but there is a version which should save the txt file (requires JMP16+ due to For Each() and Filter Each())&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

file_of_interest = "mytxtfile.txt";
zip_path = "$DOWNLOADS\test.zip";
save_path = "$DOWNLOADS\586819.txt";

za = Open(zip_path, "zip");
members_in_zip = za &amp;lt;&amp;lt; dir;

// take only .txt files
file_paths_of_interest = Filter Each({members}, members_in_zip,
	Ends With(members, file_of_interest);
);

If(N Items(file_paths_of_interest) == 0,
	Throw("Not found");
);

// Assume that only one of those files exist
file_path_of_interest = file_paths_of_interest[1];

data = za &amp;lt;&amp;lt; read(file_path_of_interest, Format("string"));
Save Text File(save_path, data);

//Open(save_path);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1672905047955.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/48820i5F5D8F629870C441/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1672905047955.png" alt="jthi_0-1672905047955.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2023 07:50:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/read-and-save-a-txt-file-from-a-subdirectory-of-a-ZIP-file/m-p/586870#M79243</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-01-05T07:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: read and save a txt file from a subdirectory of a ZIP file</title>
      <link>https://community.jmp.com/t5/Discussions/read-and-save-a-txt-file-from-a-subdirectory-of-a-ZIP-file/m-p/587014#M79253</link>
      <description>&lt;P&gt;The thing to know about zip files: they do not actually have a nested hierarchical directory structure. A zip file's directory is just a simple list of character string names. Those names might contain / or \ characters, and some zip file viewers might try to represent that as a hierarchical nest. So, the zip file member that has a name that contains &lt;EM&gt;mytextfile&lt;/EM&gt; also contains / characters in the name, and when this path is constructed&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;save text file(path1  ||  lst[k]  ||  "_"  ||  dirlist[l]  , text);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;dirlist contains "test/test/mytextfile.txt" and the resulting pathname from the concatenation probably does not exist on your computer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The word() or words() functions might be useful for separating the parts of the path.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2023 15:23:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/read-and-save-a-txt-file-from-a-subdirectory-of-a-ZIP-file/m-p/587014#M79253</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-01-05T15:23:12Z</dc:date>
    </item>
  </channel>
</rss>

