Find file name from full file path
Is there a way to extract the file name from the file full path (part of a file path) without the hassle of manipulating string?
The equivalent in Java would be:
File f = new File ("C:/some_dir/a")
f.getName() //output a
f.getFullAbsolutePath() //output c:/some_dir/a
Use
basename("C:/some_dir/a.ext")
# [1] "a.ext"
dirname("C:/some_dir/a.ext")
# [1] "C:/some_dir"
The tidyverse equivalent lives in the fs package. {fs} makes use of libuv under the hood.
library("fs")
path_file("/some/path/to/file.xyz")
#> [1] "file.xyz"
path_dir("/some/path/to/file.xyz")
#> [1] "/some/path/to"
Created on 2020-02-19 by the reprex package (v0.3.0)