recursive search function written

This commit is contained in:
Noah Swerhun 2023-11-13 00:47:16 -06:00
parent 8a430f5f14
commit 160a4bd71e
4 changed files with 52 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
/testing_grounds

7
Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "mgen"
version = "0.1.0"

8
Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "mgen"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

35
src/main.rs Normal file
View file

@ -0,0 +1,35 @@
use std::io;
fn recurse_through_c_files(dir: &str) -> io::Result<()> {
let dir = std::fs::read_dir(dir)?;
for file in dir {
let file = file?;
let file_path = file.path();
if file.path().is_dir() {
recurse_through_c_files(file_path.to_str()
.expect("filepath should be converted to string slice"))?;
}
let ext = file_path.extension()
.and_then(|v| v.to_str())
.unwrap_or_else(|| "");
if ext != "c" {
continue;
}
println!("{:?}", file.path().with_extension("o").file_name().expect("files should have names"));
todo!()
}
Ok(())
}
fn main() {
recurse_through_c_files(".").unwrap_or_else(|e| {
panic!("error: could not recurse through directory: {e}");
});
}