/// <summary> /// Enumerate the files in a given path /// </summary> /// <param name="strPath"></param> private void EnumerateFiles(string strPath, string strExts) { try { foreach (string strFile in Directory.GetFiles(strPath, strExts)) { if (bStopped == true) { return; } int intCount = 0; Match regexMatch = null; foreach (string strLine in strExRegex) { if (strLine.Length == 0) { continue; } intCount++; try { regexMatch = Regex.Match(strFile, strLine); } catch (ArgumentException) { MessageBox.Show("Exclusion regex compiliation failed on line " + intCount + ", stopping scan", "Regex error", MessageBoxButtons.OK, MessageBoxIcon.Error); bStopped = true; return; } } if (((bIgnoreTest == true && strFile.ToLower().Contains("test") == false) || bIgnoreTest == false) && (regexMatch == null || (regexMatch != null && regexMatch.Success == false))) { FileToScan file2Scan = new FileToScan(strFile, this); lock (objQueue) intQueue++; ThreadPool.QueueUserWorkItem(file2Scan.ThreadPoolCallback); } } foreach (string strDir in Directory.GetDirectories(strPath)) { if (bStopped == true) { return; } if ((bIgnoreTest == true && strDir.ToLower().Contains("test") == false) || bIgnoreTest == false) { EnumerateFiles(strDir, strExts); } } } catch (System.IO.DirectoryNotFoundException) { return; } catch (System.Exception) { return; } return; }
/// <summary> /// Enumerate the files in a given path /// </summary> /// <param name="strPath"></param> private void EnumerateFiles(string strPath, string strExts) { try { foreach (string strFile in Directory.GetFiles(strPath, strExts)) { if (bStopped == true) return; int intCount = 0; Match regexMatch = null; foreach (string strLine in strExRegex) { if (strLine.Length == 0) continue; intCount++; try { regexMatch = Regex.Match(strFile, strLine); } catch (ArgumentException) { MessageBox.Show("Exclusion regex compiliation failed on line " + intCount + ", stopping scan", "Regex error", MessageBoxButtons.OK, MessageBoxIcon.Error); bStopped = true; return; } } if (((bIgnoreTest == true && strFile.ToLower().Contains("test") == false) || bIgnoreTest == false) && (regexMatch == null || (regexMatch != null && regexMatch.Success == false))) { FileToScan file2Scan = new FileToScan(strFile, this); lock (objQueue) intQueue++; ThreadPool.QueueUserWorkItem(file2Scan.ThreadPoolCallback); } } foreach (string strDir in Directory.GetDirectories(strPath)) { if (bStopped == true) return; if ((bIgnoreTest == true && strDir.ToLower().Contains("test") == false) || bIgnoreTest == false) { EnumerateFiles(strDir, strExts); } } } catch (System.IO.DirectoryNotFoundException) { return; } catch (System.Exception) { return; } return; }