Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,17 +1,24 @@
|
|||
use std::os;
|
||||
use std::io::fs;
|
||||
use std::{env, fmt, fs, process};
|
||||
use std::io::{self, Write};
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let cwd = os::getcwd();
|
||||
let info = fs::readdir(&cwd).unwrap();
|
||||
|
||||
let mut filenames = Vec::new();
|
||||
for entry in info.iter() {
|
||||
filenames.push(entry.filename_str().unwrap());
|
||||
}
|
||||
|
||||
filenames.sort();
|
||||
for filename in filenames.iter() {
|
||||
println!("{}", filename);
|
||||
}
|
||||
let cur = env::current_dir().unwrap_or_else(|e| exit_err(e, 1));
|
||||
let arg = env::args().nth(1);
|
||||
print_files(arg.as_ref().map_or(cur.as_path(), |p| Path::new(p)))
|
||||
.unwrap_or_else(|e| exit_err(e, 2));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn print_files(path: &Path) -> io::Result<()> {
|
||||
for x in try!(fs::read_dir(path)) {
|
||||
println!("{}", try!(x).file_name().to_string_lossy());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn exit_err<T>(msg: T, code: i32) -> ! where T: fmt::Display {
|
||||
writeln!(&mut io::stderr(), "{}", msg).expect("Could not write to stderr");
|
||||
process::exit(code)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue