Open PeterCodar opened 2 years ago
I know this is not exactly what you want, but I made a few changes to exclude folders (not files) from an exclude file.
Add nuget package DotNet.Glob at https://www.nuget.org/packages/DotNet.Glob/3.0.9
frmMain.cs
public partial class frmMain : Form
{
...
private void frmMain_Load( object sender, EventArgs e )
{
...
if( System.IO.Directory.Exists( txtRoot.Text ) )
{
SetRootPath( txtRoot.Text , true);
}
else
{
SetRootPath( "" , false );
}
LoadExcludeFolders();
txtLinkRoot.Enabled = chkLinkFiles.Checked;
...
public partial class frmMain : Form
{
private static List<Glob> _globs = new List<Glob>();
private void LoadExcludeFolders()
{
GlobOptions.Default.Evaluation.CaseInsensitive = true;
string line;
using (var streamReader = new StreamReader(@"Exclude_List.txt"))
{
while ((line = streamReader.ReadLine()) != null)
{
if (string.IsNullOrWhiteSpace(line)) continue;
_globs.Add(Glob.Parse(line));
}
}
}
...
// Recursive function to get all folders and subfolders of given path path
public void DirSearch( string sDir, List<string> lstDirs, bool skipHidden, bool skipSystem, Stopwatch stopwatch )
{
if( backgroundWorker.CancellationPending ) return;
try
{
foreach( string d in System.IO.Directory.GetDirectories( sDir ) )
{
bool includeThisFolder = true;
foreach (var glob in _globs)
{
if ( glob.IsMatch(d) )
{
includeThisFolder = false;
break;
}
}
// exclude folders that have the system or hidden attr set (if required)
if ( skipHidden || skipSystem )
{
...
Exclude_List.txt
in same folder containing exe.Use glob pattern to specify folders. For example:
**\node_modules
will exclude any node_modules
folders. ** matches any number of subfolders.
It would be great if we could exclude folders by name like
$RECYCLE.BIN
or by attribute like don't show hidden/system files