@@ -29,8 +29,8 @@ export close, fclose, fsync_fd, waitpid;
29
29
export env, getenv, setenv, fdopen, pipe;
30
30
export getcwd, dll_filename, self_exe_path;
31
31
export exe_suffix, dll_suffix, sysname;
32
- export homedir, list_dir, path_is_dir , path_exists , make_absolute ,
33
- make_dir, remove_dir, change_dir, remove_file;
32
+ export homedir, list_dir, list_dir_path , path_is_dir , path_exists ,
33
+ make_absolute , make_dir, remove_dir, change_dir, remove_file;
34
34
35
35
// FIXME: move these to str perhaps?
36
36
export as_c_charp, fill_charp_buf;
@@ -452,26 +452,37 @@ fn list_dir(p: path) -> [str] {
452
452
#[ cfg( target_os = "linux" ) ]
453
453
#[ cfg( target_os = "macos" ) ]
454
454
#[ cfg( target_os = "freebsd" ) ]
455
- fn star ( ) -> str { "" }
455
+ fn star ( p : str ) -> str { p }
456
456
457
457
#[ cfg( target_os = "win32" ) ]
458
- fn star ( ) -> str { "*" }
458
+ fn star ( p : str ) -> str {
459
+ let pl = str:: len ( p) ;
460
+ if pl == 0 u || ( p[ pl - 1 u] as char != path:: consts:: path_sep
461
+ * * p[ pl - 1 u] as char != path:: consts:: alt_path_sep) {
462
+ p + path:: path_sep ( ) + "*"
463
+ } else {
464
+ p + "*"
465
+ }
466
+ }
459
467
468
+ rustrt:: rust_list_files ( star ( p) ) . filter { |filename|
469
+ !str:: eq ( filename, "." ) || !str:: eq ( filename, ".." )
470
+ }
471
+ }
472
+
473
+ #[ doc = "
474
+ Lists the contents of a directory
475
+
476
+ This version prepends each entry with the directory.
477
+ " ]
478
+ fn list_dir_path ( p : path ) -> [ str ] {
460
479
let mut p = p;
461
480
let pl = str:: len ( p) ;
462
481
if pl == 0 u || ( p[ pl - 1 u] as char != path:: consts:: path_sep
463
482
&& p[ pl - 1 u] as char != path:: consts:: alt_path_sep) {
464
483
p += path:: path_sep ( ) ;
465
484
}
466
- let mut full_paths: [ str ] = [ ] ;
467
- for vec:: each( rustrt:: rust_list_files( p + star( ) ) ) { |filename|
468
- if !str:: eq ( filename, "." ) {
469
- if !str:: eq ( filename, ".." ) {
470
- full_paths += [ p + filename] ;
471
- }
472
- }
473
- }
474
- ret full_paths;
485
+ os:: list_dir ( p) . map { |f| p + f}
475
486
}
476
487
477
488
#[ doc = "Removes a directory at the specified path" ]
@@ -750,4 +761,4 @@ mod tests {
750
761
assert ( !os:: path_exists ( "test/nonexistent-bogus-path" ) ) ;
751
762
}
752
763
753
- }
764
+ }
0 commit comments