[R] check for new files in a given directory
(Ted Harding)
Ted.Harding at manchester.ac.uk
Tue Jul 28 13:36:48 CEST 2009
On 28-Jul-09 11:23:21, Barry Rowlingson wrote:
> On Tue, Jul 28, 2009 at 12:04 PM, Andreas
> Posch<andreas.posch at tugraz.at> wrote:
>> I am trying to continuously evaluate online created data files using
>> R-algorithms. Is there any simple way to let R iteratively check for
>> new files in a given directory, load them and process them?
>>
>> Any help would be highly appreciated.
>
> list.files(dir) will tell you what files are in a directory.
>
> file.info(filepath) will tell you things about a file (modification
> time etc).
>
> Sys.sleep(n) will put R to sleep for n seconds so you don't have a
> tight loop checking the directory every millisecond.
>
> That's probably all the functionality you need, except maybe to keep
> track of what files you consider 'new', and some way of deciding if
> something has already been processed. But that's a bit
> application-specific!
>
> Barry
Snap, Baz! (Except that we played different cards -- and in view of
Andreas's follow-up, yours would be the solution for him).
However, this got me looking into '?list.files, and I see there
(R version 2.9.0 (2009-04-17)):
recursive: logical. Should the listing recurse into directories?
But:
Directories are included only if 'recursive = FALSE'.
Surely the latter is the wrong way round, and should be
Directories are included only if 'recursive = TRUE'.
(that's how it worked when I just tried it).
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 28-Jul-09 Time: 12:36:45
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list