list_dir
fn list_dir(string path) -> Result<Vec<string>, IoError> Import
Source: use io::fs::{list_dir}; compiler/src/builtin_docs/io/fs.hy Returns the names of the entries in directory path, sorted.
Only the entry names are returned (not full paths), without . and
... Returns Err(IoError::NotFound) for a missing path and
Err(IoError::NotADirectory) when path is a file.
Needs --allow-read.
Parameters#
| Name | Type |
|---|---|
path | string |
Returns#
Result<Vec<string>, IoError>
Examples#
use io::fs::{create_dir_all, list_dir, remove_dir_all};
use io::file::{write_text};
use tests::assert;
let dir = "/tmp/coil_doc_fs_list_dir";
let _ = create_dir_all(dir);
let _ = write_text("/tmp/coil_doc_fs_list_dir/b.txt", "");
let _ = write_text("/tmp/coil_doc_fs_list_dir/a.txt", "");
let names = match list_dir(dir) {
Result::Ok(v) => v,
Result::Err(_) => Vec::new(),
};
let _ = remove_dir_all(dir);
assert!(names.len() == 2);
assert!(names[0] == "a.txt" && names[1] == "b.txt");
See also#
copy: Copies the contents of filefromtoto, creating or overwritingto.create_dir: Creates the directorypath.create_dir_all: Creates the directorypathand any missing parent directories.exists: Returns whether anything exists atpath.is_dir: Returns whetherpathis a directory, following symbolic links.is_file: Returns whetherpathis a regular file, following symbolic links.is_symlink: Returns whetherpathitself is a symbolic link (the link is not followed).metadata: Returns facts aboutpathas a record, without following a final symbolic link.