@@ -401,8 +401,62 @@ extension FileManager {
401
401
guard alreadyConfirmed || shouldRemoveItemAtPath ( path, isURL: isURL) else {
402
402
return
403
403
}
404
+ let faAttributes = try ! windowsFileAttributes ( atPath: path)
405
+ if faAttributes. dwFileAttributes & DWORD ( FILE_ATTRIBUTE_DIRECTORY) == 0 {
406
+ if path. withCString ( encodedAs: UTF16 . self, DeleteFileW) == 0 {
407
+ throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
408
+ }
409
+ return
410
+ }
411
+ var dirStack = [ path]
412
+ var itemPath = " "
413
+ while let currentDir = dirStack. popLast ( ) {
414
+ do {
415
+ itemPath = currentDir
416
+ guard alreadyConfirmed || shouldRemoveItemAtPath ( itemPath, isURL: isURL) else {
417
+ continue
418
+ }
419
+ guard path. withCString ( encodedAs: UTF16 . self, RemoveDirectoryW) == 0 else {
420
+ continue
421
+ }
422
+ guard GetLastError ( ) == ERROR_DIR_NOT_EMPTY else {
423
+ throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
424
+ }
425
+ dirStack. append ( path)
426
+ var ffd : WIN32_FIND_DATAW = WIN32_FIND_DATAW ( )
427
+ let h : HANDLE = ( path + " \\ * " ) . withCString ( encodedAs: UTF16 . self, {
428
+ FindFirstFileW ( $0, & ffd)
429
+ } )
430
+ guard h != INVALID_HANDLE_VALUE else {
431
+ throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
432
+ }
433
+ defer { FindClose ( h) }
404
434
405
- NSUnimplemented ( )
435
+ repeat {
436
+ let fileArr = Array < WCHAR > (
437
+ UnsafeBufferPointer ( start: & ffd. cFileName. 0 ,
438
+ count: MemoryLayout . size ( ofValue: ffd. cFileName) ) )
439
+ let file = String ( decodingCString: fileArr, as: UTF16 . self)
440
+ itemPath = " \( currentDir) \\ \( file) "
441
+ if ( ffd. dwFileAttributes & DWORD ( FILE_ATTRIBUTE_DIRECTORY) != 0 ) {
442
+ if file != " . " && file != " .. " {
443
+ dirStack. append ( itemPath)
444
+ }
445
+ } else {
446
+ guard alreadyConfirmed || shouldRemoveItemAtPath ( itemPath, isURL: isURL) else {
447
+ continue
448
+ }
449
+ if itemPath. withCString ( encodedAs: UTF16 . self, DeleteFileW) == 0 {
450
+ throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
451
+ }
452
+ }
453
+ } while ( FindNextFileW ( h, & ffd) != 0 )
454
+ } catch {
455
+ if !shouldProceedAfterError( error, removingItemAtPath: itemPath, isURL: isURL) {
456
+ throw error
457
+ }
458
+ }
459
+ }
406
460
}
407
461
408
462
internal func _currentDirectoryPath( ) -> String {
0 commit comments