Function in io::fs compiler

is_symlink

fn is_symlink(string path) -> Result<bool, IoError>
Import
use io::fs::{is_symlink};
Source: compiler/src/builtin_docs/io/fs.hy

Returns whether path itself is a symbolic link (the link is not followed).

A missing path is Ok(false). Needs --allow-read.

Parameters#

NameType
pathstring

Returns#

Result<bool, IoError>

Examples#

use io::fs::{create_dir, is_symlink, remove_dir, remove_file, symlink};
use tests::assert;
// A directory of our own: `/tmp` itself is a link on macOS.
let dir = "/tmp/coil_doc_fs_is_symlink_dir";
let link = "/tmp/coil_doc_fs_is_symlink";
let _ = create_dir(dir);
let _ = remove_file(link);
let _ = symlink(dir, link);
let yes = match is_symlink(link) {
    Result::Ok(b) => b,
    Result::Err(_) => false,
};
let no = match is_symlink(dir) {
    Result::Ok(b) => b,
    Result::Err(_) => true,
};
let _ = remove_file(link);
let _ = remove_dir(dir);
assert!(yes && !no);

See also#

  • copy: Copies the contents of file from to to, creating or overwriting to.
  • create_dir: Creates the directory path.
  • create_dir_all: Creates the directory path and any missing parent directories.
  • exists: Returns whether anything exists at path.
  • is_dir: Returns whether path is a directory, following symbolic links.
  • is_file: Returns whether path is a regular file, following symbolic links.
  • list_dir: Returns the names of the entries in directory path, sorted.
  • metadata: Returns facts about path as a record, without following a final symbolic link.
↑ ↓ navigate ↵ open