Monitoring a Folder

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
nobaday
Posts: 36
Joined: Mon May 09, 2011 3:23 pm

Monitoring a Folder

Post by nobaday » Sun Apr 12, 2015 7:46 pm

Hi,
I've got a folder with a few hundred (to a few thousand) text files in it.
Every 3-30 seconds a new text file will appear in it.

I'd like to know what the new file is (i.e. it's filename) so I can open run so tests on its contents.

Any suggestions as to what the most elegant way to tackle this is?

Thanks!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Monitoring a Folder

Post by dunbarx » Mon Apr 13, 2015 3:22 am

Hi.

It sounds like you need to run a handler that checks the contents of that folder regularly, and compare its contents from one pass to the next.

I think that you can only get a list of files in the current defaulrFolder. But you can always set the defaultFolder property to the folder you are interested in.

Craig Newman

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Monitoring a Folder

Post by Simon » Mon Apr 13, 2015 7:04 am

We're talking "the detailed files" here.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Monitoring a Folder

Post by SparkOut » Mon Apr 13, 2015 8:17 am

Is the timing critical?
If you have a new file created every 3 to 30 seconds, would you be able to poll every (say) 20 seconds and check any new files periodically like that? Or must the first new file be dealt with before the next new file is saved in the folder?

nobaday
Posts: 36
Joined: Mon May 09, 2011 3:23 pm

Re: Monitoring a Folder

Post by nobaday » Mon Apr 13, 2015 2:19 pm

HI, timing is pretty critical. I'd like to know within a second or two.

I'm trying to build a poker calculator for online play and some tracking software. It's been done before but it's a fun little project to work on while I do the Create It course.

So once a hand is finished a text file drops in a folder. A hand is finished about every 3-30 seconds.

I could keep the folders below a few hundred to speed it up. But it would be good to have the file picked up and examined within a second or less, so the information was ready quickly to be utilized while the next hand was playing.

Thanks!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Monitoring a Folder

Post by dunbarx » Mon Apr 13, 2015 3:15 pm

Hi.

Do you know how to set up a recurring process in a handler that sends a message "in time"? Read up on the "send" command.

Craig

nobaday
Posts: 36
Joined: Mon May 09, 2011 3:23 pm

Re: Monitoring a Folder

Post by nobaday » Mon Apr 13, 2015 3:22 pm

Like a timer, then yes.

File names have a number on them, new files a higher number.

So build a recursive handler, each time it get a list off all the file names in a folder with a loop. Sort to find the highest number.

That make sense?

thanks!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Monitoring a Folder

Post by dunbarx » Mon Apr 13, 2015 5:35 pm

Right on.

But make your timer using "send in time", as opposed to a repeat loop, so that you can still work.

Craig.

nobaday
Posts: 36
Joined: Mon May 09, 2011 3:23 pm

Re: Monitoring a Folder

Post by nobaday » Mon Apr 13, 2015 5:49 pm

Oops, yes, good advice!

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: Monitoring a Folder

Post by WaltBrown » Tue Apr 14, 2015 2:55 pm

Nobaday,
I frequently create a folder called "Inbox" for this. That's where unprocessed files go. When I process them, I move them to another folder. That way I don't have very long lists of file names to search through or sort, especially if I need to frequently check for new files.
Walt
Walt Brown
Omnis traductor traditor

nobaday
Posts: 36
Joined: Mon May 09, 2011 3:23 pm

Re: Monitoring a Folder

Post by nobaday » Tue Apr 14, 2015 2:58 pm

that works, yes, I used to do similar with prepress processing of files (though with apple script). Good idea. could probably just have one file in the folder at any time....thx

Post Reply