normpath(path::AbstractString) -> AbstractString

Normalize a path, removing "." and ".." entries.


  1. Normalize a file path:

    julia> normpath("/home/user/../folder/file.txt")

    This example normalizes the file path by removing redundant .. entries.

  2. Normalize a directory path:

    julia> normpath("/home/user/../../folder")

    It normalizes the directory path by removing redundant .. entries.

  3. Handle paths with no redundant entries:
    julia> normpath("/home/user/folder/file.txt")

    If no redundant entries (. or ..) are present in the path, the function returns the same path.

Common mistake example:

julia> normpath("~/Documents/../Downloads")
ERROR: MethodError: no method matching normpath(::String)

In this example, the ~ symbol is used as a shortcut for the home directory, but the normpath function does not support it. Make sure to provide an absolute path or convert the ~ symbol to the actual home directory path before using normpath.

See Also

abspath, basename, chmod, countlines, cp, ctime, dirname, download, evalfile, expanduser, fdio, filemode, filesize, functionloc, gperm, homedir, include_string, isabspath, isblockdev, ischardev, isdir, isdirpath, isexecutable, isfifo, isfile, islink, ismount, ispath, isreadable, issetgid, issetuid, issticky, iswritable, joinpath, less, lstat, mkdir, mkpath, mktemp, mktempdir, mtime, mv, normpath, operm, poll_fd, poll_file, readall, readcsv, readdir, readdlm, readlines, readlink, realpath, relpath, rm, splitdir, splitdrive, splitext, stat, symlink, tempdir, tempname, touch, truncate, uperm, watch_file, writecsv,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: