File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
1527export const getNewUniqueFilepath = ( {
You can’t perform that action at this time.
0 commit comments