list_folder_contents

Function list_folder_contents 

Source
pub fn list_folder_contents<P: AsRef<Path>>(path: P) -> Vec<PathBuf>
Expand description

Lists the contents of a folder at the specified path.

§Arguments

§Returns

Paths of the files and folders in the specified directory (in alphabetical order). Note that folders are included in the list, but their contents are not recursively listed.

§Panics

If the provided path is not a folder or if an error occurs while reading the folder.

§Examples

§Using a string literal

use file_io::list_folder_contents;
use std::path::PathBuf;
     
let contents: Vec<PathBuf> = list_folder_contents(".vscode");

assert_eq!(
    contents,
    vec![PathBuf::from(".vscode/extensions.json"), PathBuf::from(".vscode/settings.json")]
);

§Using a Path reference

use file_io::list_folder_contents;
use std::path::{Path, PathBuf};

let contents: Vec<PathBuf> = list_folder_contents(Path::new(".vscode"));

assert_eq!(
   contents,
   vec![PathBuf::from(".vscode/extensions.json"), PathBuf::from(".vscode/settings.json")]
);