How to move backward parent folder

2020-08-09 08:41发布

问题:

In R, I'm working on "./parent/Child/A". I want to move back parent folder "child", but when I type full path. It lost many times.

回答1:

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"


回答2:

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")



回答3:

Moves up one directory in Linux

setwd("../")


回答4:

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)


标签: r file