snipt

Ctrl+h for KB shortcuts

C#

Search files in a folder by multiple file types

"*.txt|*.doc".Split('|').SelectMany(filter => System.IO.Directory.GetFiles(strFolderPath, filter)).ToArray()
https://snipt.net/embed/2c806b436178aea0859328bbde0acd75/
/raw/2c806b436178aea0859328bbde0acd75/
2c806b436178aea0859328bbde0acd75
csharp
C#
1
2019-07-16T09:24:34
True
False
False
/api/public/snipt/31332/
search-files-in-a-folder-by-multiple-file-types
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="s">&quot;*.txt|*.doc&quot;</span><span class="p">.</span><span class="n">Split</span><span class="p">(</span><span class="sc">&#39;|&#39;</span><span class="p">).</span><span class="n">SelectMany</span><span class="p">(</span><span class="n">filter</span> <span class="p">=&gt;</span> <span class="n">System</span><span class="p">.</span><span class="n">IO</span><span class="p">.</span><span class="n">Directory</span><span class="p">.</span><span class="n">GetFiles</span><span class="p">(</span><span class="n">strFolderPath</span><span class="p">,</span> <span class="n">filter</span><span class="p">)).</span><span class="n">ToArray</span><span class="p">()</span> </span></pre></div> </td></tr></table>
"file extensions", "search pattern", io, search