extract.path 

File:  jmfuns.rda

 

 

extract.path extracts the path from a string that indicates its path + file name.  It can take a vector as input; in this case, it returns the vector of paths without the filenames as output.  If an input is a path without a file name at the end, the output is simply the path. 

 

extract.path(char.vec, lower = FALSE, noDrive = FALSE,

  No.Names = TRUE, endSlash = TRUE)

 

 

 

WARNING: The output uses "/" as the separator between directories and filenames no matter whether "/" or "\\" is used in the input. 

 

By default, all paths are returned in the same case as the input. Set lower = TRUE to convert all outputted characters to lower case.

 

By default, all output elements end in a "/" (endSlash = TRUE).  Set endSlash = FALSE to omit "/" from the end of all output elements.  

 

If noDrive = FALSE (default), then extract.path returns a string that starts with a drive letter if the char.vec input starts with a drive letter.  If noDrive = TRUE, then the drive letter is removed from the output.  E.g., extract.path("C:/aa/bb/ccc.txt") returns "C:/aa/bb/" but extract.path("C:/aa/bb/ccc.txt", noDrive = TRUE) returns "/aa/bb/". 

 

Set No.Names = FALSE to return a vector of outputs that is named by the inputted path + file name vector.  Set No.Names = TRUE (default) to return an unnamed vector. 

 

In many cases, the extract.path function and the dirname function which is part of the standard R installation produce identical results, but there are cases where they differ:

 

extract.path( "e:/tm/dd/word.docm" ) = "e:/tm/dd/"

dirname( "e:/tm/dd/word.docm" ) = "e:/tm/dd"

extract.path( "e:/tm/dd/word.docm", endSlash = FALSE ) = "e:/tm/dd"

 

extract.path( "e:/tm/dd/" ) = "e:/tm/dd/"

dirname( "e:/tm/dd/" ) = "e:/tm"

extract.path( "e:/tm/dd/", endSlash = FALSE ) = "e:/tm/dd"

 

The extract.path function looks for a period in the last element of a path as a symptom of a file that is not directory; this diagnostic is overridden if there exists a directory by this name. For example, on the X220 laptop, a directory "e:\cb\cbn.exp" exists.  Therefore on the X220 laptop:

 

extract.path( "e:/cb/cbn.exp/" ) = "e:/cb/cbn.exp/"

extract.path( "e:/cb/cbn.exp" ) = "e:/cb/cbn.exp/"

dirname( "e:/cb/cbn.exp/" ) = "e:/cb"

dirname( "e:/cb/cbn.exp" ) = "e:/cb"

 

But on any computer on which there is no directory named "e:\cb\cbn.exp":

 

extract.path( "e:/cb/cbn.exp/" ) = "e:/cb/"

extract.path( "e:/cb/cbn.exp" ) = "e:/cb/"

dirname( "e:/cb/cbn.exp/" ) = "e:/cb"

dirname( "e:/cb/cbn.exp" ) = "e:/cb"

 

In the latter case, extract.path interprets the period in the directory name, cbn.exp, as indicating that cbn.exp is the name of a file with .exp as its extension. 

 

 

#-------------- The 'doc' bookmark highlights all of the documentation but not the function skeleton at the top of the file.  Use rdocToString macro to convert documentation to an R string variable  --------------------------------------------------------

Format for this html document:  Page Size = Tabloid:  11" x 17".  Note that Tabloid page size is available if Adobe PDF is set as the default printer, but not if the default printer is a physical printer that prints 8.5" x 11" standard paper.  Table widths = 9.5"