Hi,
In message "Removing ".." and "." from a file path"
on 03/07/19, Lothar Scholz <mailinglists / scriptolutions.com> writes:
|I only found the "File.expand_path" function to make a relative into
|an absolute path, but what about the ".." and "." components.
|
|I need a canonical version of a file path, so a function that would
|also remove adjacent '/' or '\' and transform to the corresponding OS
|path separator would be the best.
|
|Is there anything like this available ?
Try File.expand_path.
$ ri expand_path
------------------------------------------------------ File::expand_path
File.expand_path( fileName [, aDirString] ) -> fileName
------------------------------------------------------------------------
Converts a pathname to an absolute pathname. Relative paths are
referenced from the current working directory of the process unless
aDirString is given, in which case it will be used as the starting
point. The given pathname may start with a ``~'', which expands to
the process owner's home directory (the environment variable HOME
must be set correctly). ``~user'' expands to the named user's home
directory.
File.expand_path("~oracle/bin") #=> "/home/oracle/bin"
File.expand_path("../../bin", "/tmp/x") #=> "/bin"