feature: added function to move file
Bug: proccess in use error?
mellbacon committed
May 24, 2023 at 14:32 UTC
20bbea04716b413aa3e849a40f6dcdd6bc670b2d
1 file changed
+24
src/lib/File.ts
+24
@@ -59,6 +59,30 @@ function sortTree(tree: fs.FileEntry[]) {
59
return sortedTree;
60
}
61
62
+export async function moveFile(source: string, dest: string, file: string, type: string) {
63
+
64
+ if (!await dialog.confirm(`Are you sure you want to move "${file.split(path.sep).pop()}" from "./${source.split(path.sep).pop()}" into "./${dest.split(path.sep).pop()}?"`, {title: "Nucleus: Move File"})) {
65
+ return;
66
+ }
67
+
68
+ try {
69
+ await fs.renameFile(source, dest);
70
+ } catch (error) {
71
+ console.error(error);
72
+ }
73
+
74
+ /*
75
+ // Should use this as fallback
76
+ fs.copyFile(source, dest);
77
+ if (type === "directory") {
78
+ fs.removeDir(source);
79
+ }
80
+ else {
81
+ fs.removeFile(source);
82
+ }
83
+ */
84
+}
85
+
86
export async function saveFile(saveAs = false) {
87
const tab = get(tabs).find(t => t.active && t.isfile);
88
if (!tab.path.includes(path.sep) || tab.path === "" || saveAs) {