scoop:scoop.platform:0.1.0
src/fs/directories.scoop
Selected production source · src/fs/directories.scoop
1
package scoop.platform.fs3
import scoop.platform.system.*5
/**6
* Creates missing path components as directories, preserving already existing directories.7
*/8
public fun Path.createDirectories(mode: Int = 0x1ff) {9
try {10
this.createDirectory(mode);11
return12
}13
catch (error: PlatformException) {14
if (error.kind == PlatformErrorKind.AlreadyExists) {15
if (this.metadata().kind == FileKind.Directory)16
return17
throw error18
}19
if (error.kind != PlatformErrorKind.NotFound || this.parent == None)20
throw error21
}22
this.parent!!.createDirectories(mode)23
try {24
this.createDirectory(mode)25
}26
catch (error: PlatformException) {27
if (28
error.kind !=29
PlatformErrorKind.AlreadyExists ||30
this.metadata().kind !=31
FileKind.Directory32
)33
throw error34
}35
}37
/**38
* Recursively removes a directory tree without following symbolic-link targets.39
*/40
public fun Path.deleteRecursively() {41
if (this.metadata(followLinks = false).kind == FileKind.Directory) {42
this.entries().use {43
directory -> for (entry in directory)44
entry.path.deleteRecursively()45
}46
}47
this.delete()48
}50
/**51
* Opens an owned, single-pass cursor over this directory.52
*/53
public fun Path.entries(): DirectoryEntries = DirectoryEntries.open(this)