Skip to content

Trying to get a String representation of a file URL to use on a subprocess command line is frustrating. #5129

Open
@dabrahams

Description

@dabrahams

I know of two options that seem likely to do the right thing across platforms:

extension URL {
  var fileSystemRepresentation: String {
     self.withUnsafeFileSystemRepresentation { String(cString: $0!) }
   }
}
import System
extension URL {
  var fileSystemRepresentation: String { FilePath(self)!.string }
}

It's unclear which, if either of these, actually does the right thing on a platform like Windows, where the .path property of a URL is not in native format. Both are far too indirect.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions