Created
September 20, 2017 06:56
-
-
Save sincerefly/76d3c4767809e8bf906c5ec96bf608fb to your computer and use it in GitHub Desktop.
复制文件,以时间戳为文件名
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs; | |
use std::io; | |
use std::path::Path; | |
extern crate time; | |
fn timestamp() -> f64 { | |
let timespec = time::get_time(); | |
// 1459440009.113178 | |
let mills: f64 = timespec.sec as f64 + (timespec.nsec as f64 / 1000.0 / 1000.0 / 1000.0); | |
mills | |
} | |
fn aha() -> io::Result<()> { | |
let ts = timestamp(); | |
let ts_str = ts.to_string(); | |
let v: Vec<&str> = ts_str.split(".").collect(); | |
let filename = "funny/funny_".to_owned() + v[0] + ".db"; | |
println!("file name: {}", filename); | |
if !Path::new("funny").exists() { | |
match fs::create_dir("funny") { | |
Ok(o) => println!("{:?}", o), | |
Err(err) => println!("{:?}", err), | |
} | |
} | |
fs::copy("D:/data.db", filename)?; | |
Ok(()) | |
} | |
fn main() { | |
match aha() { | |
Ok(s) => println!("ok: {:?}", s), | |
Err(err) => println!("err: {:?}", err), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment