R: extract directory out of a path

r

Solution

You could also use the built-in function `basename`:

basename(Path)
[1] "7"

Problem

Possible Duplicate: How do I extract a file/folder_name only from a path? May I ask you how I can get the last subdirectory of a path. For example I want to get the subdirectory "7" and the following code fails: ``` Path <- "123\\456\\7" Split <- strsplit(Path, "\\") # Fails because of 'Trailing backslash' LastElement <- c[[1]][length(Split[[1]])] ``` Thank you in advance

Original source

Related problems