Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Please let the user exclude some files like $RECYCLE.BIN #33

Open
PeterCodar opened this issue Oct 8, 2021 · 1 comment

Comments

@PeterCodar
Copy link

It would be great if we could exclude folders by name like
$RECYCLE.BIN
or by attribute like
don't show hidden/system files

@preiius
Copy link

preiius commented Oct 11, 2021

I know this is not exactly what you want, but I made a few changes to exclude folders (not files) from an exclude file.

  1. Add nuget package DotNet.Glob at https://www.nuget.org/packages/DotNet.Glob/3.0.9

  2. 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;

        ...
  1. frmMain_Helpers.cs
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 )
                {
                    ...
  1. Add the exclude file named 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants