Tell when local file changes/is updated

Anyone know of a programmatic way of telling if a local file has CHANGED?

Example scenario - An app/driver uses a local file to store its configuration. A new version of same file name is uploaded by user.

Would be handy, so apps/drivers that use text files for configuration input could detect that and auto-reload the config.

Believe the create date on the file gets updated every time it changes.

1 Like

If you're looking for an "official" way to do this, I'm not aware of any (though scraping the page itself for this data would technically work given that it's there). Off the top of my head, a workaround would be to read the file, generate a hash, store that hash (probably a method available to do this...), then do something similar and compare the hashes every time you want to check if it's changed. If the file is small enough, I suppose you can skip the hash--just thinking of something that would prevent you from needing to do that.

Either way presents the issue of there being no "callback" for when it's actually changed, instead relying on you needing to check some time yourself.

1 Like

Sounds like scrape the page or hash it...

If you ever get bored @gopher.ny it may be nice to have a couple of methods here... Something to avoid scraping a page...

Maybe:

  • LocalFileExists (true false a given file name exists)
  • LocalFileCreation (tells date/time of file creation)

But since there are workarounds, maybe it isn't that important.

1 Like
http://<HubIP>:8080/hub/fileManager/json

Will give you a JSON string with all of the files, their create date, size, and type.

1 Like

Thanks.

I found an example of that, and that is what I'm now doing. Seems hacky though vs native methods.

But it works, so I'll do it!

Yes, if I were making a wish list for @gopher.ny , being able to subscribe to a file for changes with a callback/event would be super neato. I guess if it made a hub event when a file was uploaded one might be able to catch that event (?).

1 Like

I was thinking the event would more likely be the way to try and tackle this, given you are wanting to trigger something off the back of it. The methods would be nice, but the JSON output could act as a temporary solution if need be. But would obviously like all of these if possible :grin:

1 Like

The json result from the page scrape does work just fine. But granted in a polling versus event driven way.

Regardless of any use in an app or driver, I think local file changes should generate an event anyway.

1 Like

Quick question, how are you envisioning that the local file gets updated without the app/driver knowing? If it's another app/driver doing the update you can manually create a location event.

User manually uploads a new/updated file from the wen interface.