How to move backward parent folder

setwd('..')

will move up one directory without entering the absolute path. Here's an example

> getwd()
[1] "C:/Users/D/Desktop/EDABaseball"
> setwd('..')
> getwd()
[1] "C:/Users/D/Desktop"

I think you want to move back to the working directory ./parent/Child/. This can be done in 2 ways, assuming your current working directory is ./parent/Child/A

1) setwd("..")

2) setwd("./..")

3) setwd("./parent/Child")


Moves up one directory in Linux

setwd("../")

I also find dirname() function pretty useful especially if your path is saved in a variable:

mypath <- getwd()

# The path of the parent directory:
dirname(mypath)

Tags:

File

R