Skip to content

Commit

Permalink
Comments and allow creation of directories
Browse files Browse the repository at this point in the history
  • Loading branch information
FinlayDaG33k committed Jan 25, 2024
1 parent fe14476 commit 058e293
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion filesystem/folder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Logger } from "../logging/logger.ts";

export class Folder {
public constructor(
private readonly path: string
) {
}


/**
* Check whether the folder exists at the path.
*/
public async exists(): Promise<boolean> {
try {
const target = await Deno.stat(this.path);
Expand All @@ -13,4 +18,19 @@ export class Folder {
throw e;
}
}

/**
* Create the directory if it does not exist yet.
*
* @param options Options with which to create the directory
*/
public async create(options?: Deno.MkdirOptions): Promise<void> {
try {
if(await this.exists()) throw new Error('The specified folder already exists!');
} catch(e) {
Logger.warning(e.message);
}

await Deno.mkdir(this.path, options);
}
}

0 comments on commit 058e293

Please sign in to comment.