@@ -276,21 +276,26 @@ class FileAccess: RCTEventEmitter {
276
276
func stat( path: String , resolve: @escaping RCTPromiseResolveBlock , reject: @escaping RCTPromiseRejectBlock ) -> Void {
277
277
DispatchQueue . global ( ) . async {
278
278
do {
279
- let pathUrl = URL ( fileURLWithPath: path. path ( ) )
280
- let attrs = try FileManager . default. attributesOfItem ( atPath: path. path ( ) )
281
- resolve ( [
282
- " filename " : pathUrl. lastPathComponent,
283
- " lastModified " : 1000 * ( attrs [ . modificationDate] as! NSDate ) . timeIntervalSince1970,
284
- " path " : pathUrl. path,
285
- " size " : attrs [ . size] ,
286
- " type " : self . checkIfIsDirectory ( path: path) . isDirectory ? " directory " : " file "
287
- ] )
279
+ resolve ( try self . statFile ( path: path) )
288
280
} catch {
289
281
reject ( " ERR " , " Failed to stat ' \( path) '. " , error)
290
282
}
291
283
}
292
284
}
293
285
286
+ @objc ( statDir: withResolver: withRejecter: )
287
+ func statDir( path: String , resolve: @escaping RCTPromiseResolveBlock , reject: @escaping RCTPromiseRejectBlock ) -> Void {
288
+ DispatchQueue . global ( ) . async {
289
+ do {
290
+ try resolve ( FileManager . default. contentsOfDirectory ( atPath: path. path ( ) )
291
+ . map { try self . statFile ( path: " \( path) / \( $0) " ) }
292
+ )
293
+ } catch {
294
+ reject ( " ERR " , " Failed to list ' \( path) '. " , error)
295
+ }
296
+ }
297
+ }
298
+
294
299
@objc ( unlink: withResolver: withRejecter: )
295
300
func unlink( path: String , resolve: @escaping RCTPromiseResolveBlock , reject: @escaping RCTPromiseRejectBlock ) -> Void {
296
301
DispatchQueue . global ( ) . async {
@@ -340,4 +345,16 @@ class FileAccess: RCTEventEmitter {
340
345
let isDirectory = isDir. boolValue
341
346
return ( exists, isDirectory)
342
347
}
348
+
349
+ private func statFile( path: String ) throws -> [ String : Any ? ] {
350
+ let pathUrl = URL ( fileURLWithPath: path. path ( ) )
351
+ let attrs = try FileManager . default. attributesOfItem ( atPath: path. path ( ) )
352
+ return [
353
+ " filename " : pathUrl. lastPathComponent,
354
+ " lastModified " : 1000 * ( attrs [ . modificationDate] as! NSDate ) . timeIntervalSince1970,
355
+ " path " : pathUrl. path,
356
+ " size " : attrs [ . size] ,
357
+ " type " : self . checkIfIsDirectory ( path: path) . isDirectory ? " directory " : " file "
358
+ ]
359
+ }
343
360
}
0 commit comments