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.
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.
[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.