【发布时间】:2018-09-21 11:40:25
【问题描述】:
我想知道如何从路径字符串创建 URL。 这是我的代码:
let completePath = "/Volumes/MyNetworkFolder/"
do {
let items = try FileManager.default.contentsOfDirectory(atPath: completePath)
for item in items {
if item.hasDirectoryPath { //String has no member hasDirectoryPath
itemList.append(item)
}
}
} catch {
print("Failed to read dir")
let buttonPushed = dialogOKCancel(question: "Failed to read dir", text: "Map the network folder")
if(buttonPushed) {
exit(0)
}
}
我只想将文件夹添加到 itemList 数组。 hasDirectoryPath 是一个 URL 方法。 我如何更改我的代码以获取 URL 而不是字符串。
提前感谢您提供的任何帮助。
【问题讨论】:
-
无需转换。 developer.apple.com/documentation/foundation/filemanager/… 告诉你这是否是一个目录。但正如 MartinR 所说,最好从一开始就使用 URL。