Folder item count update

Hello,

I have an app that will display images on a canvas.
I have a folder that pictures are added manually to it… myImagesFolder = SpecialFolder.Desktop.child(“My Images”)
When a new picture is added to myImagesFolder I would like that new picture to be displayed in that canvas.

How does my app know when a picture is added to myImagesFolder?
I know I have to do Folderitem.count, but putting that in a timer that polls myImagesFolder.count is expensive in processing time.

Is there a less expensive way way?

Thanks.

Lennox

Check the modification date of the folder. That should always update if there’s a change like you’re looking for.

MBS plugin has something for Mac ( not for Win, cry, cry ):

https://www.monkeybreadsoftware.net/class-fseventsmbs.shtml

Thanks Thomas,
Lennox

What does it do? Use fsevents?

We have a FSEventsMBS class
http://www.monkeybreadsoftware.net/class-fseventsmbs.shtml

We also have a similar class for Windows:
http://www.monkeybreadsoftware.net/class-windowsdirectorywatchermbs.shtml

Using the timer once a second doesn’t sound expensive to me, too.

I use TT’s method (Check the modification date of the folder) and that mostly works for me. However, when a large picture or video file is copied in (or being downloaded), there could be an issue.

The Xojo Folderitem.isLocked is never True and I can normally open those files.

So far, I haven’t found a reliable way to know it’s done copying. (Like for example on OS X, Finder greys out the file while it’s copying)
Right now, I’m checking filesize with a timer but this is clearly a workaround and not very reliable.

I found FolderItem.MacType returning ‘brok’ but this is marked deprecated and there doesn’t seem to be a replacement. And I don’t know for Windows/Linux either.

Does anyone know a smart trick for that?

Shell with ls command ?

With -i      flag explanation -->    For each file, print the file's file serial number (inode number)  
With -U    flag explanation -->    Use time of file creation, instead of last modification for sorting (-t) or long output (-l).

With -u flag explanation --> Use time of last access, instead of last modification of the file for sorting (-t) or long printing (-l).

[quote=261422:@Marco Hof]I use TT’s method (Check the modification date of the folder) and that mostly works for me. However, when a large picture or video file is copied in (or being downloaded), there could be an issue.

The Xojo Folderitem.isLocked is never True and I can normally open those files.[/quote]
It may well not be locked (exclusive use) but may well be busy
Imagine you’re downloading a large file like a movie
It may be able to be played from the beginning even though the download may not be complete

[quote=261436:@Norman Palardy]It may well not be locked (exclusive use) but may well be busy
Imagine you’re downloading a large file like a movie
It may be able to be played from the beginning even though the download may not be complete[/quote]
I realize that but it can be opened for writing as well and that shouldn’t be possible.
There are actually 3:

1- Is Locked (some program has an exclusive lock on the file)
This can be checked with FolderItem

2- Is in use (some program has the file open)
On OS X, I need to Shell out to ‘lsof’ the file.

3- Is Busy (File is being copied etc.)
On OS X. I currently use the deprecated FolderItem.MacType ‘brok’. I don’t know how to handle this on Windows

Would be great if 2 and 3 would be available as FolderItem properties.

Just my penny :slight_smile:
Check for open files in folder or for specific file.
lSof

MS equivalent of FS events on OS X https://msdn.microsoft.com/en-ca/library/windows/desktop/aa365261(v=vs.85).aspx

I’d likely try & use notifications on both OSes if there are classes / plugins to do this

@Norman Palardy
That is what my plugin uses for the WindowsDirectoryWatcherMBS class.

There they go then
Use the fs events on OS X and the dir watcher on Windows and away they go