You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]{varmissingParentDirectories:[Path]=[]varcurrentPath= 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){letmissingParentDirectories=getMissingParentDirectories(of: path)formissingParentDirectoryin 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?
The text was updated successfully, but these errors were encountered:
Currently,
path.touch()
fails ifpath.parent
,path.parent.parent
, and so on doesn't exist.Currently, my workaround is as such:
Is there a native way to do this that I am missing?
The text was updated successfully, but these errors were encountered: