[R] Checking existance of a directory

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Oct 29 16:47:22 CEST 2010


On Fri, 29 Oct 2010, Ron Michael wrote:

> Hi all, I am wondering is there any way to check whether some 
> Directory exists or not, given the parent path of that directory? 
> After searching for a while I found that there is a function 
> dir.create() to create some directory. However I need to know 
> whether such directory already exists or not, otherwise I will 
> create that.

Well, as others have also pointed out, you don't need to do that (and 
I created dir.create() deliberately so you don't).

But see ?file_test and op = "-d" if you actually need to in some other 
application.  (This is linked from ?file.exists which is linked from 
?dir.create.)


> ?
> Thanks,

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list