Split Full Paths into Root, Folder, File and Extension

split_into_root_folder_file_extension(paths, n_root_parts = 0)

Arguments

paths

vector of character representing full file paths

n_root_parts

number of first path segments considered as "root"

Value

data frame with columns root, folder, file, extension, depth

Examples

paths <- c(
  "//always/the/same/root/project-1/intro.doc",
  "//always/the/same/root/project-1/logo.png",
  "//always/the/same/root/project-2/intro.txt",
  "//always/the/same/root/project-2/planning/file-1.doc",
  "//always/the/same/root/project-2/result/report.pdf"
)

split_into_root_folder_file_extension(paths)
#> Splitting paths ... ok. (0.00s) 
#>   root                                    folder       file extension depth
#> 1               //always/the/same/root/project-1  intro.doc       doc     6
#> 2               //always/the/same/root/project-1   logo.png       png     6
#> 3               //always/the/same/root/project-2  intro.txt       txt     6
#> 4      //always/the/same/root/project-2/planning file-1.doc       doc     7
#> 5        //always/the/same/root/project-2/result report.pdf       pdf     7
split_into_root_folder_file_extension(paths, n_root_parts = 6)
#> Splitting paths ... ok. (0.00s) 
#> Setting n_root_parts to 5 (was: 6) due to too few path segments
#>                               root   folder       file extension depth
#> 1 //always/the/same/root/project-1           intro.doc       doc     1
#> 2 //always/the/same/root/project-1            logo.png       png     1
#> 3 //always/the/same/root/project-2           intro.txt       txt     1
#> 4 //always/the/same/root/project-2 planning file-1.doc       doc     2
#> 5 //always/the/same/root/project-2   result report.pdf       pdf     2
split_into_root_folder_file_extension(paths, n_root_parts = 7)
#> Splitting paths ... ok. (0.00s) 
#> Setting n_root_parts to 5 (was: 7) due to too few path segments
#>                               root   folder       file extension depth
#> 1 //always/the/same/root/project-1           intro.doc       doc     1
#> 2 //always/the/same/root/project-1            logo.png       png     1
#> 3 //always/the/same/root/project-2           intro.txt       txt     1
#> 4 //always/the/same/root/project-2 planning file-1.doc       doc     2
#> 5 //always/the/same/root/project-2   result report.pdf       pdf     2