Closed ahoppen closed 1 day ago
let url = URL(fileURLWithPath: #"C:\"#) url.withUnsafeFileSystemRepresentation { filePath in print(String(cString: filePath! , encoding: .utf8)) }
prints C:. Dropping the trailing backslash is problematic here because C:\ is considered a root directory in Windows but C: is not (see table of examples in https://learn.microsoft.com/en-us/windows/win32/api/pathcch/nf-pathcch-pathcchisroot).
C:
C:\
prints
C:
. Dropping the trailing backslash is problematic here becauseC:\
is considered a root directory in Windows butC:
is not (see table of examples in https://learn.microsoft.com/en-us/windows/win32/api/pathcch/nf-pathcch-pathcchisroot).