rlv-dan / Snap2HTML

Generates directory listings contained in a single, app-like HTML files
http://www.rlvision.com/snap2html
GNU General Public License v3.0
484 stars 95 forks source link

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

Open PeterCodar opened 2 years ago

PeterCodar commented 2 years ago

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 commented 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.

  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.