Skip to content

Latest commit

 

History

History
38 lines (32 loc) · 1.25 KB

README.md

File metadata and controls

38 lines (32 loc) · 1.25 KB

NuGet

YellowCounter.FileSystemState

Like FileSystemWatcher except you control when the state is checked. This allows it to work well for scheduled tasks instead of relying on continuous jobs.

Sample

    class Program
    {
        const string FileName = "state.bin";
        static void Main(string[] args)
        {
            var state = new FileSystemState(Environment.CurrentDirectory, "*.txt", new EnumerationOptions { RecurseSubdirectories = true });

            if (File.Exists(FileName))
            {
                // If the file exists, get file system state from the file
                using (var stream = File.OpenRead(FileName))
                {
                    state.LoadState(stream);
                }
            }
            else
            {
                // Otherwise, get the current file system state
                state.LoadState();
            }

            var changes = state.GetChanges();    // Looks for changes in file system state

            using (var stream = File.OpenWrite(FileName))
            {
                state.SaveState(stream);
            }
        }
    }