Skip to content

Instantly share code, notes, and snippets.

@Ruszrok
Created March 16, 2016 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ruszrok/3d7d7b6a468f39aaeacc to your computer and use it in GitHub Desktop.
Save Ruszrok/3d7d7b6a468f39aaeacc to your computer and use it in GitHub Desktop.
use std::io;
use std::io::Write;
use std::io::BufReader;
use std::io::BufRead;
use std::fs;
use std::fs::File;
static LOG_NAME: &'static str = "log.txt";
fn include_file(file_name: &String) -> bool{
file_name != &".DS_Store".to_string() &&
file_name != &"log_generator".to_string() &&
file_name != &"log_generator.rs".to_string() &&
file_name != &LOG_NAME.to_string()
}
fn create_log(f : &File) -> io::Result<()>{
for entry in try!(fs::read_dir("./")) {
let entry = try!(entry);
let is_dir = try!(fs::metadata(entry.path())).is_dir();
if !is_dir {
let file_name = entry.path().file_name().unwrap().to_string_lossy().into_owned();
if include_file(&file_name){
append_file(file_name, f);
// println!("Name: {}", file_name);
}
}
}
Ok(())
}
fn append_file (file_name : String, mut log_file : &File) -> io::Result<()>
{
let title = format!("--------- {} ---------\n", file_name);
log_file.write_all(title.as_bytes());
let mut f = File::open(file_name).unwrap();
let mut file = BufReader::new(&f);
for line in file.lines() {
write!(log_file, "{}\n", line.unwrap());
// log_file.write_fmt("{}\n", line.unwrap());
}
Ok(())
}
fn main(){
let mut f = File::create(LOG_NAME).unwrap();
create_log(&f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment