68 lines
1.6 KiB
C#
68 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Collections;
|
|
|
|
namespace ITFInstaller
|
|
{
|
|
public class FileSearch
|
|
{
|
|
ArrayList _extensions;
|
|
ArrayList _excludedFolders;
|
|
|
|
bool _recursive;
|
|
public ArrayList SearchExtensions
|
|
{
|
|
get { return _extensions; }
|
|
}
|
|
|
|
public ArrayList ExcludedFolders
|
|
{
|
|
get { return _excludedFolders; }
|
|
}
|
|
|
|
|
|
|
|
public bool Recursive
|
|
{
|
|
get { return _recursive; }
|
|
set { _recursive = value; }
|
|
}
|
|
|
|
public FileSearch()
|
|
{
|
|
_extensions = ArrayList.Synchronized(new ArrayList());
|
|
_excludedFolders = ArrayList.Synchronized(new ArrayList());
|
|
_recursive = true;
|
|
}
|
|
|
|
public FileInfo[] Search(string path)
|
|
{
|
|
DirectoryInfo root = new DirectoryInfo(path);
|
|
ArrayList subFiles = new ArrayList();
|
|
foreach (FileInfo file in root.GetFiles())
|
|
{
|
|
if (_extensions.Contains(file.Extension))
|
|
{
|
|
subFiles.Add(file);
|
|
}
|
|
}
|
|
|
|
if (_recursive)
|
|
{
|
|
foreach (DirectoryInfo directory in root.GetDirectories())
|
|
{
|
|
if (_excludedFolders.Contains(directory.FullName))
|
|
continue;
|
|
|
|
subFiles.AddRange(Search(directory.FullName));
|
|
}
|
|
}
|
|
|
|
return (FileInfo[])subFiles.ToArray(typeof(FileInfo));
|
|
}
|
|
}
|
|
|
|
}
|