Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
add folderExists to fsUtils.ts to check if local template folder …
Browse files Browse the repository at this point in the history
…exists (#62)

and use it in `deleteFolder` in `fsUtils.ts` too
  • Loading branch information
RandomFractals committed Jun 4, 2023
1 parent 3aeaf5d commit e7aba4d
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/utils/fsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,26 @@ import {
} from 'vscode';

/**
* Deletes a folder from the open project workspace.
* Checks if the given folder exists using workspace.fs API.
*
* @param folder Folder Uri.
*/
export async function folderExists(folder: Uri): Promise<boolean> {
try {
const fileStat = await workspace.fs.stat(folder);
if (fileStat.type === FileType.Directory) {
return true;
}
}
catch (error) {
return false;
}
return false;
}

/**
* Deletes a folder from the open project workspace
* ussing workspace.fs API.
*
* @param relativeFolderPath Relative folder path to delete.
* @returns True if the folder is deleted, and false otherwise.
Expand All @@ -15,14 +34,14 @@ export async function deleteFolder(relativeFolderPath: string): Promise<boolean>
if (workspaceFolders) {
for (const folder of workspaceFolders) {
const folderUri: Uri = Uri.joinPath(folder.uri, relativeFolderPath);
try {
const fileStat = await workspace.fs.stat(folderUri);
if (fileStat.type === FileType.Directory) {
await workspace.fs.delete(folderUri, {recursive: true});
if (await folderExists(folderUri)) {
try {
await workspace.fs.delete(folderUri, { recursive: true });
return true;
}
}
catch (error) {
catch (error) {
return false;
}
}
}
}
Expand Down

0 comments on commit e7aba4d

Please sign in to comment.