create nested folders in current directory in R?
Asked Answered
D

1

6

I want to create nested folders, I used dir.create() to create say /test1/project/code/example/ in current directory

cidr <- getwd()
mkfldr <- "/test1/project/code/example"
dir.create(cidr,mffldr)

but it generate like

Warning message: In dir.create(file.path(cidr, mkfldr)) : cannot create dir 'C:\Users\sharmb5\Documents\R script_RR\test1\project\code/example', reason 'No such file or directory'

and there is no creation of folders. If I use showWarning = FALSE, now it not giving the above warning but still not required folders are there.

suggest any method to create all these folders all in once instead of creating one by one.

Appreciations to your answer in advance!

Dight answered 29/1, 2019 at 6:14 Comment(6)
Use the recursive argument of dir.createVenettavenezia
From ?dir.create: "recursive: logical. Should elements of the path other than the last be created? If true, like the Unix command 'mkdir -p'."Karoline
@Venettavenezia I already used that recursive argument but it created folders up to \test1\project\code not entire path \test1\project\code/example which is required.Dight
@Karoline Then how the last one to be created?Dight
@Hardikgupta not fully but partially solved i.e. up to "\test1\project\code/example".Dight
yeshh it resolved. Thanks to all of you for your suggestions and answers.Dight
G
13

This should do it:

cidr <- getwd()
mkfldr <- "test1/project/code/example"
dir.create(file.path(cidr, mkfldr), recursive = TRUE)
Gujranwala answered 29/1, 2019 at 7:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.