Note that there are some explanatory texts on larger screens.

plurals
  1. POsearching for a string in a full path c#
    primarykey
    data
    text
    <p>I have a Large Array of paths to MP3 files. I am searching this array to find anything in the entire path to match something being searched for. Its only returning matches in the file name, not the path.</p> <p>old :</p> <pre><code>using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; namespace test { class Program { static void Main(string[] args) { _search("ant"); Console.Read(); } static void _search(string var) { string[] mp3 = new String[1]; mp3 = Directory.GetFiles("c:\","*.mp3","SearchOption.AllDirectories); string[] temp = new string[1]; int x = 0; for (int i = 0; i &lt; mp3.Length; i++) { if (mp3[i].Contains(var)) { temp[x] = mp3[i]; x++; Array.Resize(ref temp, x + 1); } } _writeArray(temp); } static void _writeArray(string[] array) { for (int i = 0; i &lt; array.Length; i++) Console.Write(array[i] + "\n"); } } } </code></pre> <p>new: </p> <pre><code>using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; namespace test { class Program { static void Main(string[] args) { List&lt;string&gt; search = searchSong("ant"); foreach (string song in search) { Console.WriteLine(song); } } static List&lt;string&gt; searchSong(string value) { value = value.ToLower(); List&lt;string&gt; songs = new List&lt;string&gt;(); String[] mp3 = null; mp3 = Directory.GetFiles(@"c:\users\owner\music\metal\sybreed", "*.mp3", SearchOption.AllDirectories).ToArray(); foreach (string item in mp3) { string LowerCaseItem = item.ToLower(); if (LowerCaseItem.Contains(value)) { songs.Add(item); } } return songs; } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload