<div dir="ltr"><div>@ Denis:</div><div>- I forgot to mention: The files are under windows.</div><div><br></div><div>@ Claus:</div><div>- [...]
I create a list of all
files in that directory and read all of them [....]</div><div><br></div><div>Yes , this is what I see when using "listfiles"</div><div>What I am searching for would be:</div><div>- choose a directory<br></div><div>- choose a file extension</div><div><br></div><div>--> create a list of all files with that extension in :</div><div>-> the directory</div><div>-> in all sub-directories</div><div><br></div><div>I do doubt that there is a ready-to-use-function for that, so my question is: How to do it the most elegant way?</div><div><br></div><div>I do not have a full aproach for this, yet.</div><div>However I feel, that the first thing to do is, to get absolut pathnames to all folders,</div><div>Afterwards I would scan each folder for the specifi file type.<br></div><div><br></div><div><br></div><div>Mh...still thinking.</div><div>Philipp<br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Mo., 27. Sept. 2021 um 17:52 Uhr schrieb Claus Futtrup <<a href="mailto:cfuttrup@gmail.com">cfuttrup@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div>Hi Philipp</div>
<div><br>
</div>
<div>This piece of code used to work
(haven't checked with Scilab 6.1.1). First I ask the user to
select one file in the directory, then I create a list of all
files in that directory and read all of them:</div>
<div><br>
</div>
<div>
<pre style="font-style:normal;font-size:12px;font-family:Monospaced"><span style="color:rgb(74,85,219)">[</span><span style="color:rgb(0,0,0)">units</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">typs</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">nams</span><span style="color:rgb(74,85,219)">]</span><span style="color:rgb(92,92,92)">=</span><span style="color:rgb(50,185,185)">file</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span> <span style="color:rgb(100,174,100);font-style:italic">// nams(1) = script file name incl. path</span>
<span style="color:rgb(0,0,0)">fpathname</span><span style="color:rgb(92,92,92)">=</span><span style="color:rgb(50,185,185)">strsplit</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">nams</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">1</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">,</span> <span style="color:rgb(74,85,219)">[</span><span style="color:rgb(50,185,185)">filesep</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">]</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(0,0,0)">scriptpath</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">get_absolute_file_path</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">fpathname</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(255,170,0)">$</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(50,185,185)">printf</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(188,143,143)">Please select a .txt measurement file\n</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(74,85,219)">[</span><span style="color:rgb(0,0,0)">filetoread</span> <span style="color:rgb(0,0,0)">pathtofile</span><span style="color:rgb(74,85,219)">]</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">uigetfile</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(188,143,143)">*.txt</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">scriptpath</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(188,143,143)">Choose measurement file</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(100,174,100);font-style:italic">// For a start, assume script file is in the same directory as the data,</span>
<span style="color:rgb(100,174,100);font-style:italic">// but don</span><span style="color:rgb(100,174,100);font-style:italic">'</span><span style="color:rgb(100,174,100);font-style:italic">t be sure, read pathtofile and use it instead.</span>
<span style="color:rgb(0,0,0)">readfile</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(0,0,0)">pathtofile</span> <span style="color:rgb(92,92,92)">+</span> <span style="color:rgb(188,143,143)">"</span><span style="color:rgb(188,143,143)">\</span><span style="color:rgb(188,143,143)">"</span> <span style="color:rgb(92,92,92)">+</span> <span style="color:rgb(0,0,0)">filetoread</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(160,32,240)">if</span> <span style="color:rgb(50,185,185)">length</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">filetoread</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">></span><span style="color:rgb(188,143,143)">4</span> <span style="color:rgb(160,32,240)">then</span> <span style="color:rgb(100,174,100);font-style:italic">// one char + .txt expected, i.e. length</span><span style="color:rgb(100,174,100);font-style:italic">></span><span style="color:rgb(100,174,100);font-style:italic">4</span>
<span style="color:rgb(100,174,100);font-style:italic">// If user doesn</span><span style="color:rgb(100,174,100);font-style:italic">'</span><span style="color:rgb(100,174,100);font-style:italic">t select any file, the above check prevents a crash</span>
<span style="color:rgb(50,185,185)">chdir</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">pathtofile</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(160,32,240)">if</span> <span style="color:rgb(0,0,0)">verbose</span> <span style="color:rgb(160,32,240)">then</span> <span style="color:rgb(50,185,185)">printf</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(188,143,143)"> MSG: File found, thanks!\n</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span> <span style="color:rgb(160,32,240)">end</span></pre>
</div>
<div>...<br>
</div>
<div><br>
</div>
<div>
<pre style="font-style:normal;font-size:12px;font-family:Monospaced"><span style="color:rgb(100,174,100);font-style:italic">// Analyze - find all files in the path, who</span><span style="color:rgb(100,174,100);font-style:italic">'</span><span style="color:rgb(100,174,100);font-style:italic">s filename is an</span>
<span style="color:rgb(100,174,100);font-style:italic">// integer, which means - we expect it to be an angle.</span>
<span style="color:rgb(0,0,0)">filelist</span><span style="color:rgb(92,92,92)">=</span><span style="color:rgb(174,92,176);text-decoration:underline">listfiles</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">pathtofile</span> <span style="color:rgb(92,92,92)">+</span> <span style="color:rgb(188,143,143)">"</span><span style="color:rgb(188,143,143)">\*.txt</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span></pre>
</div>
<div><br>
</div>
<div>...</div>
<div><br>
</div>
<div>
<pre style="font-style:normal;font-size:12px;font-family:Monospaced"><span style="color:rgb(0,0,0)">imax</span><span style="color:rgb(92,92,92)">=</span><span style="color:rgb(50,185,185)">max</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(50,185,185)">size</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">filelist</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span></pre>
</div>
<div>...</div>
<div><br>
</div>
<div>
<pre style="font-style:normal;font-size:12px;font-family:Monospaced"><span style="color:rgb(50,185,185)">printf</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(188,143,143)">Loop %i times: </span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">imax</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(160,32,240)">for</span> <span style="color:rgb(0,0,0)">i</span><span style="color:rgb(92,92,92)">=</span><span style="color:rgb(188,143,143)">1</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">imax</span> <span style="color:rgb(160,32,240)">do</span>
<span style="color:rgb(50,185,185)">printf</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(188,143,143)">%i </span><span style="color:rgb(188,143,143)">"</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(100,174,100);font-style:italic">// Show progress</span>
<span style="color:rgb(74,85,219)">[</span><span style="color:rgb(0,0,0)">path</span> <span style="color:rgb(0,0,0)">fname</span> <span style="color:rgb(0,0,0)">extension</span><span style="color:rgb(74,85,219)">]</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">fileparts</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">filelist</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(160,32,240)">if</span> <span style="color:rgb(50,185,185)">isnum</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">fname</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(160,32,240)">then</span> <span style="color:rgb(100,174,100);font-style:italic">// check if fname (a string) contains</span>
<span style="color:rgb(0,0,0)">d</span><span style="color:rgb(92,92,92)">=</span><span style="color:rgb(174,92,176);text-decoration:underline">evstr</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">fname</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span> <span style="color:rgb(100,174,100);font-style:italic">// a number, and convert to number</span></pre>
</div>
<div><br>
</div>
<div>I hope this is inspiring.</div>
<div><br>
</div>
<div>Cheers,</div>
<div>Claus</div>
<div><br>
</div>
<div>On 27-09-2021 16:50, P M wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>Dear All,</div>
<div><br>
</div>
<div>I need to find and list all files of a specific type on my
hard drive....How to do that in the most elegant way?</div>
<div><br>
</div>
<div>E.g.: <br>
</div>
<div><br>
</div>
<div>- find all *.txt files in "D:\"</div>
<div>- also find all '*.txt' files in each sub - directory,
sub-sub-directory, ..etc<br>
</div>
<div>- create a list that stores the absolute path names to the
*.txt files.</div>
<div><br>
</div>
<div>I am aware of</div>
<div>- dir</div>
<div>- findfiles</div>
<div>- listfiles</div>
<div>- ls<br>
</div>
<div><br>
</div>
<div>But they only seem to list the files in a dedicated folder.</div>
<div><br>
</div>
<div>Is there a function, that also searches all sub-folders
automatically?</div>
<div><br>
</div>
<div>Thank you,</div>
<div>Philipp<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
users mailing list
<a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a>
<a href="http://lists.scilab.org/mailman/listinfo/users" target="_blank">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
</blockquote>
<p><br>
</p>
</div>
_______________________________________________<br>
users mailing list<br>
<a href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a><br>
<a href="http://lists.scilab.org/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.scilab.org/mailman/listinfo/users</a><br>
</blockquote></div>