@@ -629,27 +629,34 @@ export class FileSystemAccess {
629629 private enumEntities ( path : string , callback : ( entity : { path : string ; name : string ; extension : string } ) => boolean , onError ?: ( error ) => any ) {
630630 try {
631631 const fileManager = NSFileManager . defaultManager ;
632- let files : NSArray < string > ;
633- try {
634- files = fileManager . contentsOfDirectoryAtPathError ( path ) ;
635- } catch ( ex ) {
636- if ( onError ) {
637- onError ( new Error ( "Failed to enum files for folder '" + path + "': " + ex ) ) ;
638- }
632+ if ( ! this . folderExists ( path ) ) {
633+ console . error ( `Failed to enum files for folder '${ path } ': no folder exists at path` ) ;
634+ return ;
635+ }
639636
637+ const enumerator = fileManager . enumeratorAtPath ( path ) ;
638+ if ( ! enumerator ) {
639+ console . error ( `Failed to enum files for folder '${ path } ': unable to create directory enumerator` ) ;
640640 return ;
641641 }
642642
643- for ( let i = 0 ; i < files . count ; i ++ ) {
644- const file = files . objectAtIndex ( i ) ;
643+ let file = enumerator . nextObject ( ) as string ;
644+ while ( file ) {
645+ // Only surface direct children to match the previous shallow enumeration contract.
646+ if ( enumerator . level > 1 ) {
647+ file = enumerator . nextObject ( ) as string ;
648+ continue ;
649+ }
645650
646651 const info = {
647652 path : this . concatPath ( path , file ) ,
648653 name : file ,
649654 extension : '' ,
650655 } ;
651656
652- if ( ! this . folderExists ( this . joinPath ( path , file ) ) ) {
657+ if ( this . folderExists ( this . joinPath ( path , file ) ) ) {
658+ enumerator . skipDescendants ( ) ;
659+ } else {
653660 info . extension = this . getFileExtension ( info . path ) ;
654661 }
655662
@@ -658,6 +665,8 @@ export class FileSystemAccess {
658665 // the callback returned false meaning we should stop the iteration
659666 break ;
660667 }
668+
669+ file = enumerator . nextObject ( ) as string ;
661670 }
662671 } catch ( ex ) {
663672 if ( onError ) {
0 commit comments