Can remove files and directories.

This commit is contained in:
Andrés N. Robalino
2019-07-17 14:51:18 -05:00
parent c53b1610f0
commit 514da5bfa7
9 changed files with 160 additions and 8 deletions

View File

@@ -1,11 +1,13 @@
use std::path::PathBuf;
#![allow(dead_code)]
pub use std::path::PathBuf;
#[macro_export]
macro_rules! nu {
($out:ident, $cwd:expr, $commands:expr) => {
use std::error::Error;
use std::io::prelude::*;
use std::process::{Command, Stdio};
pub use std::io::prelude::*;
pub use std::process::{Command, Stdio};
pub use std::error::Error;
let commands = &*format!(
"
@@ -75,6 +77,22 @@ macro_rules! nu_error {
};
}
pub fn create_file_at(full_path: &str) {
std::fs::write(PathBuf::from(full_path), "fake data".as_bytes()).expect("can not create file");
}
pub fn file_exists_at(full_path: &str) -> bool {
PathBuf::from(full_path).exists()
}
pub fn delete_directory_at(full_path: &str) {
std::fs::remove_dir_all(PathBuf::from(full_path)).expect("can not remove directory");
}
pub fn create_directory_at(full_path: &str) {
std::fs::create_dir(PathBuf::from(full_path)).expect("can not create directory");
}
pub fn executable_path() -> PathBuf {
let mut buf = PathBuf::new();
buf.push("target");