Last active
August 29, 2015 14:24
-
-
Save stevekm/0a5cc483d6077f33f7c7 to your computer and use it in GitHub Desktop.
Check to see if directory exists. If so, delete the directory and re-create it. If not, make the directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the directories we are using | |
DIRS<-c("/home/user/DataOutput/", | |
"/home/user/DataOutput/A/", | |
"/home/user/DataOutput/B/") | |
# iterate through the vector of directories | |
for(i in 1:length(DIRS)){ | |
if(dir.exists(DIRS[i])){ | |
# delete the directory | |
unlink(DIRS[i],recursive = T,force = T) | |
# make a new copy of the directory | |
dir.create(DIRS[i],mode = "0770") | |
} else {dir.create(DIRS[i],mode = "0770")} | |
} | |
# when running scripts, we need to make sure old results are removed | |
# or they might accidentally be used in place of new data if the script fails | |
# to do this, delete the data output directories we will be working with | |
# and make them over again each time the script is run | |
# this runs in R | |
# this works well when these commands are at the start of a script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment