This seems to be a simple question but I can't find any answer online. Suppose my current working directory is C:/parent_folder/sub_folder
, and I want to get C:/parent_folder
in Julia.
Edit: I have a solution using PyCall but are there any better solutions, preferably without the need of importing libraries of other languages?
using PyCall
function get_parent_directory()
pathlib = pyimport("pathlib")
path = pathlib.Path(pwd())
s = string(path.parent)
return split(s, "\'")[2]
end
get_parent_directory()
Use File 's getParentFile() method and String. lastIndexOf() to retrieve just the immediate parent directory.
Getwd functionis used to get the current working directory in Golang, the function returns the rooted path name and if the current directory can be reached via multiple paths, the function can return any one of them.
An alternative solution is to use dirname
:
dirname(pwd())
This should work for you:
cd(pwd, "..")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With