Skip to content

Commit 6b80b41

Browse files
authored
Merge pull request #2328 from gmittert/PeeringInside
Fix up _contentsOfDir on Windows
2 parents 39e3587 + 0ea7ab3 commit 6b80b41

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Foundation/FileManager+Win32.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@ extension FileManager {
189189
}
190190

191191
internal func _contentsOfDir(atPath path: String, _ closure: (String, Int32) throws -> () ) throws {
192-
try path.withCString(encodedAs: UTF16.self) {
192+
guard path != "" else {
193+
throw NSError(domain: NSCocoaErrorDomain, code: CocoaError.fileReadInvalidFileName.rawValue, userInfo: [NSFilePathErrorKey : NSString(path)])
194+
}
195+
try (path + "\\*").withCString(encodedAs: UTF16.self) {
193196
var ffd: WIN32_FIND_DATAW = WIN32_FIND_DATAW()
194197

195198
let hDirectory: HANDLE = FindFirstFileW($0, &ffd)
@@ -204,8 +207,9 @@ extension FileManager {
204207
String(decodingCString: $0, as: UTF16.self)
205208
}
206209
}
207-
208-
try closure(path, Int32(ffd.dwFileAttributes))
210+
if path != "." && path != ".." {
211+
try closure(path, Int32(ffd.dwFileAttributes))
212+
}
209213
} while FindNextFileW(hDirectory, &ffd)
210214
}
211215
}

0 commit comments

Comments
 (0)