-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
47 lines (43 loc) · 1.15 KB
/
options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const { window } = require("vscode");
const fs = require("fs");
const folderPath = __dirname + "/.folderPath.env";
async function selectFolder() {
const options = {
canSelectMany: false,
openLabel: "Open",
canSelectFolders: true,
canSelectFiles: false,
};
const fileUri = await window.showOpenDialog(options);
if (fileUri && fileUri[0]) {
let selectFolderPath = fileUri[0].fsPath;
if (isFolderEmpty(selectFolderPath)) {
window.showWarningMessage(
"Selected folder is empty. Please select a valid folder!"
);
} else {
process.env.FOLDER_PATH = selectFolderPath;
try {
fs.writeFileSync(folderPath, `FOLDER_PATH=${selectFolderPath}`);
window.showInformationMessage(`Folder selected!`);
} catch (e) {
console.log(e);
}
}
} else {
let message = "Folder not found! Please try again.";
window.showInformationMessage(message);
}
}
// Function to check if a folder is empty
function isFolderEmpty(path) {
try {
const files = fs.readdirSync(path);
return files.length === 0;
} catch (error) {
return true;
}
}
module.exports = {
selectFolder,
};