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
You could also use the built-in function basename
:
basename(Path)
[1] "7"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With