Skip to content

Commit e9feba0

Browse files
authored
bug fix (#763)
1 parent 24d30fa commit e9feba0

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

apps/obsidian/src/utils/file.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
import { TAbstractFile, TFolder, Vault, normalizePath } from "obsidian";
1+
import { Vault, normalizePath } from "obsidian";
22

3-
export const checkAndCreateFolder = async (folderpath: string, vault: Vault) => {
3+
export const checkAndCreateFolder = async (
4+
folderpath: string,
5+
vault: Vault,
6+
) => {
47
if (!folderpath) return;
58
const normalizedPath = normalizePath(folderpath);
69

7-
const abstractItem = vault.getAbstractFileByPath(normalizedPath);
8-
if (abstractItem instanceof TFolder) return;
9-
if (abstractItem instanceof TAbstractFile) {
10-
throw new Error(`${normalizedPath} exists as a file`);
10+
const existingFolder = await vault.adapter.exists(normalizedPath, false);
11+
if (existingFolder) return;
12+
13+
try {
14+
await vault.createFolder(normalizedPath);
15+
} catch (e) {
16+
const message = e instanceof Error ? e.message : String(e);
17+
if (
18+
message.includes("Folder already exists") ||
19+
message.includes("already exists")
20+
) {
21+
return;
22+
}
23+
throw e;
1124
}
12-
await vault.createFolder(normalizedPath);
1325
};
1426

1527
export const getNewUniqueFilepath = ({

0 commit comments

Comments
 (0)