Skip to content

vault

This module provides utility functions for working with the Obsidian Vault.

Interface Description
CleanupEmptyFoldersParams Parameters for cleanupEmptyFolders.
ContentArguments Arguments for process.
CopySafeParams Parameters for copySafe.
GetAbstractFilePathSafeParams Parameters for getAbstractFilePathSafe.
GetOrCreateAbstractFileSafeParams Parameters for getOrCreateAbstractFileSafe.
GetSafeRenamePathParams Parameters for getSafeRenamePath.
InvokeWithFileSystemLockParams Parameters for invokeWithFileSystemLock.
IsChildOrSelfParams Parameters for isChildOrSelf.
IsChildParams Parameters for isChild.
ProcessOptions Options for process.
ProcessParams Parameters for process.
RenameSafeParams Parameters for renameSafe.
Function Description
cleanupEmptyFolders Cleans up empty folders according to the given EmptyFolderBehavior.
copySafe Copies a file or folder safely in the vault. A folder is copied with its whole subtree, empty subfolders included.
createFolderSafe Creates a folder safely in the specified path.
createTemporaryFile Creates a temporary file in the vault with parent folders if needed.
createTemporaryFolder Creates a temporary folder in the vault with parent folders if needed.
deleteEmptyFolder Deletes an empty folder. A folder the vault index still holds but the disk has already lost is not empty: it is nothing to delete, so it is left alone rather than handed to the trash as a missing path.
deleteEmptyFolderHierarchy Removes empty folder hierarchy starting from the given folder. The walk stops at the first folder that is not empty or no longer exists on disk.
getAbstractFilePathSafe Gets a safe path for a file or folder.
getAvailablePath Gets an available path for a file in the vault.
getFilePathSafe Gets a safe file path for a file or folder.
getFolderPathSafe Gets a safe folder path for a file or folder.
getMarkdownFilesSorted Retrieves an array of Markdown files from the app’s vault and sorts them alphabetically by their file path.
getNoteFilesSorted Retrieves an array of all note files from the app’s vault and sorts them alphabetically by their file path.
getOrCreateAbstractFileSafe Gets or creates an abstract file safely in the specified path. If the file already exists, it will be returned. If the file does not exist, it will be created and returned.
getOrCreateFileSafe Gets or creates a file safely in the specified path. If the file already exists, it will be returned. If the file does not exist, it will be created and returned.
getOrCreateFolderSafe Gets or creates a folder safely in the specified path. If the folder already exists, it will be returned. If the folder does not exist, it will be created and returned.
getSafeRenamePath Gets a safe rename path for a file.
invokeWithFileSystemLock Invokes a function with the file system lock.
isChild Checks if a path or file is a child of another path or file.
isChildOrSelf Checks if a path or file is a child or self of another path or file.
isEmptyFolder Checks if a folder is empty.
listSafe Safely lists the files and folders at the specified path in the vault.
process Processes a file with retry logic, updating its content based on a provided value or function.
readSafe Reads the content of a file safely from the vault. It covers the case when the file was removed during the reading. This is NOT a pure read: it calls saveNote first, which saves any open editor view of the note that has unsaved changes, so the content it returns is what the user sees. Do not call it from an automatic trigger that only decides whether to act. See getCacheSafe in @mnaoumov/obsidian-lib/metadata-cache for why.
renameSafe Renames a file safely in the vault. If the new path already exists, the file will be renamed to an available path.
saveNote Saves the specified note in the Obsidian app. Calls view.save() on every open markdown view of the note that has unsaved changes. This is a write, and several helpers whose names read as reads call it: readSafe, and getCacheSafe, getFrontmatterSafe and getBacklinksForFileSafe in @mnaoumov/obsidian-lib/metadata-cache.
trashSafe Trashes an abstract file safely from the vault.
Enum Description
CreateFolderSafeResult The result of createFolderSafe.
EmptyFolderBehavior A behavior for handling empty folders during cleanup.
InvokeFileActionSafeResult The result of invokeFileActionSafe.