From: matz@... (Yukihiro Matsumoto) Date: 2003-07-19T21:16:31+09:00 Subject: Re: Removing ".." and "." from a file path Hi, In message "Removing ".." and "." from a file path" on 03/07/19, Lothar Scholz 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"