Skip to main content

Commands: Delete

Syntax

#Commands: Delete

There are two methods that allow to delete a single file or multiple files at once.

The DeleteAsync method is used to delete a file.

Syntax

Task DeleteAsync(string filename, Etag etag = null);
Parameters
filenamestringThe name of a file to be deleted
etagEtagThe current file Etag, used for concurrency checks (null skips check)

Return Value
TaskA task that represents the asynchronous delete operation.

Example

await store.AsyncFilesCommands.DeleteAsync("/movies/intro.avi");

DeleteByQueryAsync

The DeleteByQueryAsync is used to delete files that match the specified query.

Syntax

Task DeleteByQueryAsync(string query);
Parameters
querystringThe Lucene query

Return Value
TaskA task that represents the asynchronous delete operation.

Example

In order to delete files located in /temp folder except from ones in its subdirectories, run the following code:

await store.AsyncFilesCommands.DeleteByQueryAsync("__directoryName:/temp AND __level:2");

To delete a file, RavenFS needs to remove a lot of information related to this file. In order to respond to the user quickly, the file is just renamed and a delete marker is added to its metadata. The actual delete is performed by a periodic task, which ensures that all the requested deletes will be accomplished even in the presence of a server restarts in the middle.