Is there a way to create a file and its directory if missing?
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- swift
调研方向
Start by reading the Path.touch(), Path.mkdir(), and parent APIs referenced in the issue. Decide whether recursive parent creation belongs in touch or a separate API, then verify the chosen behavior when one or more parent directories are missing and when they already exist.
由索引模型根据 Issue 内容生成。
描述
Currently, path.touch() fails if path.parent, path.parent.parent, and so on doesn't exist.
Currently, my workaround is as such:
/// Get the missing parent directories of a path, shallow to deep.
/// - Parameter path: The path to get the missing parent directories of.
/// - Returns: An array of the missing parent directories.
func getMissingParentDirectories(of path: Path) -> [Path] {
var missingParentDirectories: [Path] = []
var currentPath = path.parent
while !currentPath.exists {
missingParentDirectories.append(currentPath)
currentPath = currentPath.parent
}
return missingParentDirectories.reversed()
}
/// Create the missing parent directories of a path, shallow to deep.
/// - Parameter path: The path to create the missing parent directories of.
func createMissingParentDirectories(of path: Path) {
let missingParentDirectories = getMissingParentDirectories(of: path)
for missingParentDirectory in missingParentDirectories {
do {
try missingParentDirectory.mkdir()
} catch {
fatalError("Could not create the directory \(missingParentDirectory)")
}
}
}
Is there a native way to do this that I am missing?
- 主要语言
- Swift
- 星标
- 959
- 派生
- 40
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
mxcl/Path.swift 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 42/100
mxcl/Path.swift#88 · 2 条评论 ·
-
难度 5/5 一周以上 新手友好度 10/100
mxcl/Path.swift#66 ·
-
难度 3/5 1-2 天 新手友好度 25/100
mxcl/Path.swift#17 · 1 条评论 ·
相似的 Issue
-
area/kotlin
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
cable-report
难度 2/5 1-3 小时 新手友好度 67/100
darrylmorley/whatcable#656 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
omlahore/RemoveMacAI#67 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 82/100
521xueweihan/HelloGitHub#4049 ·
-
[quality] macOSScreenshotLocation(): configured-location branch (ScreenshotFiles.swift:30) never executes under swift test可能已有人在做 @arteeh 今天认领。 未关闭agent/quality agent/reviewer help wanted kind/test stage/040-covered-by-pr testing
难度 2/5 1-3 小时 新手友好度 72/100
hivecommons/hotshot#249 · 4 条评论 ·
维护者通常 1 天内回复