CreateDirectories.R
From Organic Design wiki
(Redirected from Create Directories.R)
<R> dir.exists <- function(x, curdir = ".", rootdir) {
- -------------------------------------------------------------------------------------- #
- Author : Marcus Davy
- This is a recursive program to take in a string such as:
- foo/fodda/fi, and create subdirectories foo, fodda, and fi
- from the current directory location (if they don't already exist)
- Note: It does the same work as the function dir.create in the base package, e.g.
- dir.create("foo/fodda/fi", recursive=TRUE)
- The recursive option is like Unix's 'mkdir -p foo/fodda/fi'.
- -------------------------------------------------------------------------------------- #
if( missing(rootdir)) { rootdir <- getwd() } setwd(curdir) x <- unlist(strsplit(x,"/")) if( !file.exists(x[1]) ){ dir.create(x[1]) print(paste("Creating", file.path(getwd(), x[1]))) } curdir <- x[1]
if(length(x)==1) { setwd(rootdir) } else { return(dir.exists(x[-1], curdir = curdir, rootdir = rootdir)) }
} </R>