pwd
pwd() -> AbstractString
Get the current working directory.
Examples
In the Julia programming language, the pwd()
function is used to retrieve the current working directory.
julia> pwd()
"/path/to/current/directory"
Common examples of its use:
-
Print the current working directory:
julia> println(pwd()) /path/to/current/directory
This example prints the current working directory to the console.
-
Store the current working directory in a variable:
julia> current_dir = pwd() "/path/to/current/directory"
It assigns the current working directory to the variable
current_dir
for later use. - Change the directory and retrieve the updated current working directory:
julia> cd("/path/to/new/directory") julia> println(pwd()) /path/to/new/directory
This example changes the directory to
/path/to/new/directory
and then prints the updated current working directory.
Common mistake example:
julia> current_dir = pwd
"/path/to/current/directory"
In this example, the mistake is missing the parentheses ()
when calling pwd()
. Without the parentheses, pwd
refers to the function itself rather than invoking it. Always remember to include ()
when calling functions in Julia.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.