Commit 6bbb801f by Jos van den Oever

Use convenient fs::canonicalize function

parent 368f3f49
extern crate qml;
use std::fs::read_dir;
use std::io;
use std::fs;
use std::path::{Path, PathBuf};
use qml::*;
......@@ -49,7 +49,7 @@ Q_OBJECT!{
fn list_dir(dir: &Path, model: &mut QDirModel) -> io::Result<()> {
// get sorted list of readable entries
let mut entries = read_dir(dir)?.filter_map(|e| e.ok()).collect::<Vec<_>>();
let mut entries = fs::read_dir(dir)?.filter_map(|e| e.ok()).collect::<Vec<_>>();
entries.sort_by(|a, b| a.file_name().cmp(&b.file_name()));
......@@ -79,9 +79,9 @@ fn main() {
let mut engine = QmlEngine::new();
// Create a model with files.
let current_dir = PathBuf::from(".")
.expect("Could not canonicalize the directory.");
let dir_str = ".";
let current_dir = fs::canonicalize(dir_str)
.expect(&format!("Could not canonicalize {}.", dir_str));
let mut dir_model = QDirModel::new();
list_dir(&current_dir, &mut dir_model).expect("Could not read directory.");
engine.set_and_store_property("dirModel", &dir_model);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment