10 examples of 'javascript get current directory' in JavaScript

Every line of 'javascript get current directory' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
9export function currentDirectory() {
10 return process.cwd().replace(/\\/g, "/");
11}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

180getCurrentDirectory(): string { return "." }
333getCurrentDirectory(): string {
334 return "";
335}
30getCurrentDirectory(): string { return "."; }
11export function getCwd() {
12 let type = os.type().toString();
13 let cwd = null;
14
15 switch (type) {
16 case 'Windows_NT':
17 case 'Linux':
18 cwd = process.cwd();
19 break;
20 case 'Darwin':
21 cwd = electron.remote.app.getPath('userData');
22 break;
23 }
24
25 return cwd;
26}
24export function resolveCurrentFolderPath(): string | null {
25 const activeEditor = vscode.window.activeTextEditor;
26 const filePath = activeEditor && activeEditor.document.fileName;
27 return resolveFolderPath(filePath || '');
28}
45function dir() {
46 var out = process.cwd().split('/').pop(-1);
47 return out;
48}
314function setCurrentWorkingDirectory() {
315 try {
316 if (process.platform === 'win32') {
317 process.env['VSCODE_CWD'] = process.cwd(); // remember as environment variable
318 process.chdir(path.dirname(app.getPath('exe'))); // always set application folder as cwd
319 } else if (process.env['VSCODE_CWD']) {
320 process.chdir(process.env['VSCODE_CWD']);
321 }
322 } catch (err) {
323 console.error(err);
324 }
325}
91function get_parent_folder(directory) {
92 if (directory != null) {
93 var pos = directory.lastIndexOf('/');
94 if (pos == -1) {
95 return '';
96 } else {
97 return directory.substring(0, pos);
98 }
99 }
100 return '';
101}
119getDirectory() {
120 return this.directoryInput.value.toString();
121}

Related snippets