splitdrive(path::AbstractString) -> (AbstractString,AbstractString)

On Windows, split a path into the drive letter part and the path part. On Unix systems, the first component is always the empty string.


  1. Splitting a Windows path:

    julia> splitdrive("C:\\Users\\Username\\Documents\\file.txt")
    ("C:", "\\Users\\Username\\Documents\\file.txt")

    In this example, the given Windows path is split into the drive letter part ("C:") and the path part ("\Users\Username\Documents\file.txt").

  2. Handling Unix paths:

    julia> splitdrive("/home/username/file.txt")
    ("", "/home/username/file.txt")

    On Unix systems, where there is no drive letter, the first component of the path is always an empty string. In this example, the Unix path is split into an empty string and the path ("/home/username/file.txt").

  3. Splitting a path with a network drive on Windows:
    julia> splitdrive("\\\\server\\share\\folder\\file.txt")
    ("\\\\server\\share", "\\folder\\file.txt")

    When dealing with network paths on Windows, the drive letter part includes the server and share name. In this example, the network path is split into the drive letter part ("\\server\share") and the path part ("\folder\file.txt").

Common mistake example:

julia> splitdrive("/path/file.txt")
("", "/path/file.txt")

In this example, a Unix path is provided to splitdrive. It correctly returns an empty string as the drive letter part since Unix paths do not have drive letters.

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: