Code Monkey home page Code Monkey logo

filewatch's Introduction

Filewatch

Branch Status
Master Master
Develop Develop

Single header folder/file watcher in C++11 for windows and linux, with optional regex filtering

Install:

Drop FileWatch.hpp in to your include path, and you should be good to go.

Examples:

On linux or none unicode windows change std::wstring for std::string or std::filesystem (boost should work as well).

Simple:
filewatch::FileWatch<std::wstring> watch(
	L"C:/Users/User/Desktop/Watch/Test"s, 
	[](const std::wstring& path, const filewatch::Event change_type) {
		std::wcout << path << L"\n";
	}
);
Change Type:
filewatch::FileWatch<std::wstring> watch(
	L"C:/Users/User/Desktop/Watch/Test"s, 
	[](const std::wstring& path, const filewatch::Event change_type) {
		std::wcout << path << L" : ";
		switch (change_type)
		{
		case filewatch::Event::added:
			std::cout << "The file was added to the directory." << '\n';
			break;
		case filewatch::Event::removed:
			std::cout << "The file was removed from the directory." << '\n';
			break;
		case filewatch::Event::modified:
			std::cout << "The file was modified. This can be a change in the time stamp or attributes." << '\n';
			break;
		case filewatch::Event::renamed_old:
			std::cout << "The file was renamed and this is the old name." << '\n';
			break;
		case filewatch::ChangeType::renamed_new:
			std::cout << "The file was renamed and this is the new name." << '\n';
			break;
		};
	}
);
Regex:

Using the standard regex libary you can filter the file paths that will trigger. When using wstring you will have to use std::wregex

filewatch::FileWatch<std::wstring> watch(
	L"C:/Users/User/Desktop/Watch/Test"s,
	std::wregex(L"test.*"),
	[](const std::wstring& path, const filewatch::Event change_type) {
		std::wcout << path << L"\n";
	}
);
Using std::filesystem:
filewatch::FileWatch<std::filesystem::path> watch(
	L"C:/Users/User/Desktop/Watch/Test"s, 
	[](const std::filesystem::path& path, const filewatch::Event change_type) {
		std::wcout << std::filesystem::absolute(path) << L"\n";		
	}
);
Works with relative paths:
filewatch::FileWatch<std::filesystem::path> watch(
	L"./"s, 
	[](const std::filesystem::path& path, const filewatch::Event change_type) {
		std::wcout << std::filesystem::absolute(path) << L"\n";		
	}
);
Single file watch:
filewatch::FileWatch<std::wstring> watch(
	L"./test.txt"s, 
	[](const std::wstring& path, const filewatch::Event change_type) {
		std::wcout << path << L"\n";		
	}
);

filewatch's People

Contributors

thomasmonkman avatar thomasmonkmanholition avatar

Watchers

 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.