Skip to content

This is a C# library whose purpose is to detect directory changes and return all renamed, moved, created, and deleted files. It is able to spot renamed files without requiring the use of hash-code comparisons or real time tracking, even if a million file with same content (duplicated) got renamed at the same millisecond.

License

Notifications You must be signed in to change notification settings

AbdelhamidLarachi/FileSystemWatcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FileSystemWatcher FileSystemWatcher License FileSystemWatcher NuGet version

FileSystemWatcher is a C# library whose purpose is to detect directory changes and return all renamed, moved, created, and deleted files. It is able to spot renamed files without requiring the use of hashcode comparisons or real time tracking. It targets netstandard2.1+.

Examples

Use it like the following example :

namespace FileSystemWatcher
{
    class Program
    {
        static void Main(string[] args)
        {
            // Choose a directory to watch
            string directory = @"/Users/nginx-iwnl/Desktop/Project";

            // Initialize directory 
            FileSystemWatcher.BeginInit(directory);

            // Optional: using ignore patterns
            string[] ignore = { ".exe", "/node_modules" };
            FileSystemWatcher.BeginInit(directory, ignore);
        }
    }
}
  • Apply changes to your directory ..... (rename, delete...)
  • Get results by calling EndInit
using System;

namespace FileSystemWatcher
{
    class Program
    {
        static void Main(string[] args)
        {
            // Choose a directory to watch
            string directory = @"/Users/nginx-iwnl/Desktop/Project";

            // End directory watch
            ChangeModel result = FileSystemWatcher.EndInit(directory);

            // Print Result
            Console.WriteLine("Directory has changed : {0}", result.HasChanged);
            Console.WriteLine("\n----Created Files:");

            foreach (var file in result.Changes.created)
                Console.WriteLine(file);

            Console.WriteLine("\n----Deleted Files:");

            foreach (var file in result.Changes.deleted)
                Console.WriteLine(file);

            Console.WriteLine("\n----Renamed Files:");

            foreach (var file in result.Changes.renamed)
                Console.WriteLine("{0} => {1}", file.prevName, file.name);

            Console.WriteLine("\n----Changed Files:");

            foreach (var file in result.Changes.changed)
                Console.WriteLine("{0} with {1}% match", file.filename, file.match);
        }
    }
}

expected result:

provided implementations:

  • created files
  • deleted files
  • renamed files
  • moved files
  • changed files with similarity percentage %

About

This is a C# library whose purpose is to detect directory changes and return all renamed, moved, created, and deleted files. It is able to spot renamed files without requiring the use of hash-code comparisons or real time tracking, even if a million file with same content (duplicated) got renamed at the same millisecond.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages