How to trigger an event when a file changes, and get the path to this file?



private:
    static FDelegateHandle WatcherHandle;


cpp:



static FDirectoryWatcherModule &DirectoryWatcherModule = FModuleManager::LoadModuleChecked<FDirectoryWatcherModule>(TEXT("DirectoryWatcher"));

FDelegateHandle FMyClass::WatcherHandle = FDelegateHandle();


DirectoryWatcherModule.Get()->RegisterDirectoryChangedCallback_Handle
(
    MY_FOLDER_PATH
    , IDirectoryWatcher::FDirectoryChanged::CreateRaw
    (
        this, &FMyClass::OnProjectDirectoryChanged
    )
    , FMyClass::WatcherHandle
    , IDirectoryWatcher::WatchOptions::IncludeDirectoryChanges
);




void FMyClass::OnProjectDirectoryChanged(const TArray<FFileChangeData> & Data)
{
    // ... do stuff
}


1 Like