MCPcopy Index your code
hub / github.com/PowerShell/vscode-powershell / checkIfFileOrDirectoryExists

Function checkIfFileOrDirectoryExists

src/utils.ts:56–73  ·  view source on GitHub ↗
(
    targetPath: string | vscode.Uri,
    type: vscode.FileType,
)

Source from the content-addressed store, hash-verified

54// Check that the file or directory exists in an asynchronous manner that relies
55// solely on the VS Code API, not Node's fs library, ignoring symlinks.
56async function checkIfFileOrDirectoryExists(
57 targetPath: string | vscode.Uri,
58 type: vscode.FileType,
59): Promise<boolean> {
60 if (targetPath === "") {
61 return false;
62 }
63 try {
64 const stat: vscode.FileStat = await vscode.workspace.fs.stat(
65 targetPath instanceof vscode.Uri
66 ? targetPath
67 : vscode.Uri.file(targetPath),
68 );
69 return (stat.type & type) !== 0;
70 } catch {
71 return false;
72 }
73}
74
75export async function checkIfFileExists(
76 filePath: string | vscode.Uri,

Callers 2

checkIfFileExistsFunction · 0.85
checkIfDirectoryExistsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected