@@ -261,6 +261,45 @@ pub fn test_while_readonly<P: AsRef<Path>, F: FnOnce() + std::panic::UnwindSafe>
261261 success. unwrap ( ) ;
262262}
263263
264+ /// Browse the directory `path` non-recursively and return all files which respect the parameters
265+ /// outlined by `closure`.
266+ #[ track_caller]
267+ pub fn shallow_find_files < P : AsRef < Path > , F : Fn ( & PathBuf ) -> bool > (
268+ path : P ,
269+ closure : F ,
270+ ) -> Vec < PathBuf > {
271+ let mut matching_files = Vec :: new ( ) ;
272+ for entry in fs_wrapper:: read_dir ( path) {
273+ let entry = entry. expect ( "failed to read directory entry." ) ;
274+ let path = entry. path ( ) ;
275+
276+ if path. is_file ( ) && closure ( & path) {
277+ matching_files. push ( path) ;
278+ }
279+ }
280+ matching_files
281+ }
282+
283+ /// Returns true if the filename at `path` starts with `prefix`.
284+ pub fn has_prefix < P : AsRef < Path > > ( path : P , prefix : & str ) -> bool {
285+ path. as_ref ( ) . file_name ( ) . is_some_and ( |name| name. to_str ( ) . unwrap ( ) . starts_with ( prefix) )
286+ }
287+
288+ /// Returns true if the filename at `path` has the extension `extension`.
289+ pub fn has_extension < P : AsRef < Path > > ( path : P , extension : & str ) -> bool {
290+ path. as_ref ( ) . extension ( ) . is_some_and ( |ext| ext == extension)
291+ }
292+
293+ /// Returns true if the filename at `path` does not contain `expected`.
294+ pub fn not_contains < P : AsRef < Path > > ( path : P , expected : & str ) -> bool {
295+ !path. as_ref ( ) . file_name ( ) . is_some_and ( |name| name. to_str ( ) . unwrap ( ) . contains ( expected) )
296+ }
297+
298+ /// Returns true if the filename at `path` ends with `suffix`.
299+ pub fn has_suffix < P : AsRef < Path > > ( path : P , suffix : & str ) -> bool {
300+ path. as_ref ( ) . file_name ( ) . is_some_and ( |name| name. to_str ( ) . unwrap ( ) . ends_with ( suffix) )
301+ }
302+
264303/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
265304/// available on the platform!
266305#[ track_caller]
0 commit comments