use std::fs::File;
use std::io;
use std::io::Read;
use std::path::Path;
use tokio::io::AsyncReadExt;
use walkdir::{DirEntry, WalkDir};
use crate::rulog::rulog;
pub fn list_all_files(dir: &str) -> Vec<std::path::PathBuf> {
WalkDir::new(dir)
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| e.file_type().is_file())
.map(|e| e.path().to_path_buf())
.collect()
}
pub fn list_all_files_rs(dir: &str) -> Vec<String> {
let allfiles=list_all_files(dir);
let mut files=Vec::new();
for file in allfiles {
rulog::info(file.to_str().unwrap() );
if file.extension().and_then(|s| s.to_str()) == Some("rs") {
files.push(file.display().to_string());
}
}
files
}
pub fn is_rs(f:std::path::PathBuf)->bool{
return f.extension().and_then(|s| s.to_str()) == Some("rs")
}
pub fn read_file(file_name :&str) -> Result<String, io::Error> {
let mut file = File::open(file_name); let mut contents = String::new();
file?.read_to_string(&mut contents); Ok(contents)
}
pub fn check_file_exist(pathf:String) -> bool { Path::new(&pathf).exists()
}