Commands: Delete
There are two methods that allow to delete a single file or multiple files at once.
DeleteAsync
The DeleteAsync method is used to delete a file.
Syntax
Task DeleteAsync(string filename, Etag etag = null);
Parameters | ||
---|---|---|
filename | string | The name of a file to be deleted |
etag | Etag | The current file Etag, used for concurrency checks (null skips check) |
Return Value | |
---|---|
Task | A 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 | ||
---|---|---|
query | string | The Lucene query |
Return Value | |
---|---|
Task | A 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");
Delete on the server side
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.