Giter Club home page Giter Club logo

mab.dotignore's Introduction

MAB.DotIgnore

NuGet

Load and parse .gitignore files (or any text files using the same syntax) to produce an IgnoreList which can be used to ignore specific files and folders during (for example) a recursve file copy operation.

The goal of this library is to implement the same file matching behaviour Git uses to determine which files to ignore when adding to a commit. Please feel free to submit any issues with examples or pull requests, if you find instances where this isn't the case.

Basic usage:

.gitignore file contents

*.txt

C# code

var ignores = new IgnoreList(@"path\to\my\.gitignore");

ignores.IsIgnored(@"path\to\ignore.txt"); // Returns true
ignores.IsIgnored(@"path\to\include.cs"); // Returns false

Example usage

A quick example illustrating how you might integrate an IgnoreList into a copy routine:

public static void CopyWithIgnores(DirectoryInfo source, DirectoryInfo target, IgnoreList ignores)
{
    foreach (DirectoryInfo dir in source.GetDirectories().Where(d => !ignores.IsIgnored(d)))
        CopyWithIgnores(dir, target.CreateSubdirectory(dir.Name), ignores);

    foreach (FileInfo file in source.GetFiles().Where(f => !ignores.IsIgnored(f)))
        file.CopyTo(Path.Combine(target.FullName, file.Name));
}

var source = new DirectoryInfo(@"c:\source");
var destination = new DirectoryInfo(@"c:\destination");

var ignores = new IgnoreList(@"c:\source\.gitignore");

CopyWithIgnores(source, destination, ignores);

Note: this code is not an example of good or efficient recursive copying: it's just here to illustrate the use of this library.

mab.dotignore's People

Contributors

markashleybell avatar atifaziz avatar nojaf avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.