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. Thanks, [[alternative HTML version deleted]]
Hi, something like this perhaps, if("myfolder"%in%dir()==FALSE) dir.create("myfolder") Command dir.create() is not overwriting an existing folder. Best regards, Andris On Fri, Oct 29, 2010 at 12:08 PM, Ron Michael <ron_michael70 at yahoo.com> 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. > > Thanks, > > > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >
Try this: if(!file.info('myfolder')$isdir) dir.create('myfolder') On Fri, Oct 29, 2010 at 9:08 AM, Ron Michael <ron_michael70@yahoo.com>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. > > Thanks, > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 29/10/10 13:08, 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.Just use dir.create(showWarnings=FALSE) This will create the directory if it does not exist, and do nothing if it does. If showWarnings=TRUE, it will give you a warning that the directory exists. Cheers, Rainer> > Thanks, > > > [[alternative HTML version deleted]] > > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.- -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel: +33 - (0)9 53 10 27 44 Cell: +27 - (0)8 39 47 90 42 Fax (SA): +27 - (0)8 65 16 27 82 Fax (D) : +49 - (0)3 21 21 25 22 44 Fax (FR): +33 - (0)9 58 10 27 44 email: Rainer at krugs.de Skype: RMkrug -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkzKtV0ACgkQoYgNqgF2egpRSACgiB498c+M0ICsoJMZxS051lkw k4UAn0XAI52H1LtRZAJSUQcB6haK8xWO =66jA -----END PGP SIGNATURE-----
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