Scoop API

scoop:scoop.platform:0.1.0

src/fs/directories.scoop

Selected production source · src/fs/directories.scoop

1package scoop.platform.fs
3import scoop.platform.system.*
5/**
6 * Creates missing path components as directories, preserving already existing directories.
7 */
8public fun Path.createDirectories(mode: Int = 0x1ff) {
9 try {
10 this.createDirectory(mode);
11 return
12 }
13 catch (error: PlatformException) {
14 if (error.kind == PlatformErrorKind.AlreadyExists) {
15 if (this.metadata().kind == FileKind.Directory)
16 return
17 throw error
18 }
19 if (error.kind != PlatformErrorKind.NotFound || this.parent == None)
20 throw error
21 }
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.Directory
32 )
33 throw error
34 }
37/**
38 * Recursively removes a directory tree without following symbolic-link targets.
39 */
40public 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()
50/**
51 * Opens an owned, single-pass cursor over this directory.
52 */
53public fun Path.entries(): DirectoryEntries = DirectoryEntries.open(this)