-
Notifications
You must be signed in to change notification settings - Fork 20
/
fileparts.R
28 lines (27 loc) · 945 Bytes
/
fileparts.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#' MATLAB fileparts function
#'
#' Get the various parts of a file with path string.
#'
#' @param filename.with.path A string of a filename with a path
#'
#' @return A list with the following components:
#' \item{pathname}{The path name}
#' \item{filename}{The file name}
#' \item{fileext}{The file extension}
#'
#' @note This is a modified version of the same function in the matlab R-package.
#'
#' @family MATLAB
#' @example tests/testthat/examples_fcn_doc/examples_fileparts.R
#' @export
#' @keywords internal
## Function written to match MATLAB function
## Author: Andrew Hooker
fileparts <- function(filename.with.path){
pathname <- dirname(filename.with.path)
filename <- basename(filename.with.path)
fileext <- gsub(".*(\\.[^\\.]*)$","\\1",filename)
filename <- gsub("(.*)(\\.[^\\.]*)$","\\1",filename)
if(fileext==filename) fileext <- ""
return(list(pathname=pathname,filename=filename,fileext=fileext))
}