@@ -405,30 +405,36 @@ extension FileManager {
405
405
guard alreadyConfirmed || shouldRemoveItemAtPath ( path, isURL: isURL) else {
406
406
return
407
407
}
408
- let faAttributes = try windowsFileAttributes ( atPath: path)
408
+ let url = URL ( fileURLWithPath: path)
409
+ var fsrBuf : [ WCHAR ] = Array < WCHAR > ( repeating: 0 , count: Int ( MAX_PATH) )
410
+ _CFURLGetWideFileSystemRepresentation ( url. _cfObject, false , & fsrBuf, Int ( MAX_PATH) )
411
+ let length = wcsnlen_s ( & fsrBuf, fsrBuf. count)
412
+ let fsrPath = String ( utf16CodeUnits: & fsrBuf, count: length)
413
+
414
+ let faAttributes = try windowsFileAttributes ( atPath: fsrPath)
409
415
if faAttributes. dwFileAttributes & DWORD ( FILE_ATTRIBUTE_DIRECTORY) == 0 {
410
- if !path . withCString ( encodedAs: UTF16 . self, DeleteFileW) {
416
+ if !fsrPath . withCString ( encodedAs: UTF16 . self, DeleteFileW) {
411
417
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
412
418
}
413
419
return
414
420
}
415
- var dirStack = [ path ]
421
+ var dirStack = [ fsrPath ]
416
422
var itemPath = " "
417
423
while let currentDir = dirStack. popLast ( ) {
418
424
do {
419
425
itemPath = currentDir
420
426
guard alreadyConfirmed || shouldRemoveItemAtPath ( itemPath, isURL: isURL) else {
421
427
continue
422
428
}
423
- guard !path . withCString ( encodedAs: UTF16 . self, RemoveDirectoryW) else {
429
+ guard !itemPath . withCString ( encodedAs: UTF16 . self, RemoveDirectoryW) else {
424
430
continue
425
431
}
426
432
guard GetLastError ( ) == ERROR_DIR_NOT_EMPTY else {
427
433
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
428
434
}
429
- dirStack. append ( path )
435
+ dirStack. append ( itemPath )
430
436
var ffd : WIN32_FIND_DATAW = WIN32_FIND_DATAW ( )
431
- let h : HANDLE = ( path + " \\ * " ) . withCString ( encodedAs: UTF16 . self, {
437
+ let h : HANDLE = ( itemPath + " \\ * " ) . withCString ( encodedAs: UTF16 . self, {
432
438
FindFirstFileW ( $0, & ffd)
433
439
} )
434
440
guard h != INVALID_HANDLE_VALUE else {
0 commit comments