I\'m writing a program in which one of the components must be able to take a path it is given (such as /help/index.html
, or /help/
) and a relative path
Stephen's answer is correct, but I wanted to add something to save future readers some time:
You should note functions within the path package assume the separator is /
. When using the example above, I kept getting the output .
since I had a Window's file path using \
.
If you're not manipulating URLs, consider using the filepath package which uses the OS's directory separator.
E.g. When running on Windows:
path.Dir("C:\\Users\\Darren\\Desktop\\file.txt")
filepath.Dir("C:\\Users\\Darren\\Desktop\\file.txt")
Returns:
.
C:\Users\Darren\Desktop