Skip to content

Commit

Permalink
Hooks: Directory commands (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson authored Feb 19, 2024
1 parent ac48004 commit 56adf16
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bin/src/modules/hook/libraries/rfs/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,24 @@ pub mod path_functions {
}
list
}

#[rhai_fn(global, pure)]
pub fn create_dir(path: &mut PathBuf) -> bool {
std::fs::create_dir(path).is_ok()
}

#[rhai_fn(global, pure)]
pub fn create_dir_all(path: &mut PathBuf) -> bool {
std::fs::create_dir_all(path).is_ok()
}

#[rhai_fn(global, pure)]
pub fn remove_dir(path: &mut PathBuf) -> bool {
std::fs::remove_dir(path).is_ok()
}

#[rhai_fn(global, pure)]
pub fn remove_dir_all(path: &mut PathBuf) -> bool {
std::fs::remove_dir_all(path).is_ok()
}
}
20 changes: 20 additions & 0 deletions bin/src/modules/hook/libraries/vfs/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,24 @@ pub mod path_functions {
}
Ok(list)
}

#[rhai_fn(global, pure)]
pub fn create_dir(path: &mut VfsPath) -> bool {
path.create_dir().is_ok()
}

#[rhai_fn(global, pure)]
pub fn create_dir_all(path: &mut VfsPath) -> bool {
path.create_dir_all().is_ok()
}

#[rhai_fn(global, pure)]
pub fn remove_dir(path: &mut VfsPath) -> bool {
path.remove_dir().is_ok()
}

#[rhai_fn(global, pure)]
pub fn remove_dir_all(path: &mut VfsPath) -> bool {
path.remove_dir_all().is_ok()
}
}
32 changes: 32 additions & 0 deletions book/rhai/library/filesystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,35 @@ Writes the string to the file. Can be called multiple times to append to the fil
```ts
HEMTT_VFS.join("docs").join("readme.md").create_file().write("Hello World!"); // Writes "Hello World!" to the file
```

### `create_dir()`

Creates the directory.

```ts
HEMTT_VFS.join("docs").create_dir(); // Creates the docs folder
```

### `create_dir_all()`

Creates the directory and all parent directories.

```ts
HEMTT_VFS.join("docs").join("images").create_dir_all(); // Creates the images folder and the docs folder if they don't exist
```

### `remove_dir()`

Removes the directory.

```ts
HEMTT_VFS.join("docs").remove_dir(); // Removes the docs folder
```

### `remove_dir_all()`

Removes the directory and all its contents.

```ts
HEMTT_VFS.join("docs").remove_dir_all(); // Removes the docs folder and all its contents
```

0 comments on commit 56adf16

Please sign in to comment.