@@ -261,6 +261,40 @@ pub fn test_while_readonly<P: AsRef<Path>, F: FnOnce() + std::panic::UnwindSafe>
261
261
success. unwrap ( ) ;
262
262
}
263
263
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` is not in `expected`.
294
+ pub fn name_not_among < P : AsRef < Path > > ( path : P , expected : & [ & ' static str ] ) -> bool {
295
+ path. as_ref ( ) . file_name ( ) . is_some_and ( |name| !expected. contains ( & name. to_str ( ) . unwrap ( ) ) )
296
+ }
297
+
264
298
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
265
299
/// available on the platform!
266
300
#[ track_caller]
0 commit comments