I need to search files of the extension mp3 and many more from the whole C Drive and store only its path in specific list string,currently I'm just printing on the Console I get repetitive results too .I just want to skip even if one file is found.How is it possible to search all type of extension file apart with mp3 and avi and many more
List<string> filesmediaFound = new List<string>();
string machinename = Environment.MachineName;
string wmifilepath = @"\\" + machinename + @"\root\CIMV2";
string fileSearchQuery = @"SELECT * FROM CIM_DataFile WHERE Drive='C:' AND Extension = 'mp3'";
// ObjectQuery querystring = new ObjectQuery(fileSearchQuery);
using (ManagementObjectSearcher search = new ManagementObjectSearcher(wmifilepath, fileSearchQuery))
{
foreach (ManagementObject result in search.Get())
{
Console.WriteLine( result["Path"].ToString());
}
}
If you just want to search for files then you can use Directory class in System.IO