> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# WdDeleteRemoteFiles

> WdDeleteRemoteFiles

# WdDeleteRemoteFiles

Performs best-effort deletion of files and directories on a remote device.

**Introduced in:** [RIT 0.0.13-preview](/reference/remoting/release-versions#release-versions).

## Syntax

```cpp theme={null}
HRESULT WdDeleteRemoteFiles(  
         _In_z_ const char* remoteDevice,  
         _In_z_ const char* remoteFolderPath,  
         _In_opt_ const WdDeleteOptions* deleteOptions,  
         _In_opt_ const WdDeleteSearchOptions* searchOptions,  
         _In_opt_ const WdDeleteStatusCallbacks* statusCallbacks,  
         _In_opt_ WdCancellationHandle cancellationHandle  
);  
```

### Parameters

`_In_z_ remoteDevice`\
Type: **const char\***

The address or name of the remote device (UTF-8), for example `"192.168.1.100"` or `"MyDevKit"`.

`_In_z_ remoteFolderPath`\
Type: **const char\***

The path on the remote device to delete (UTF-8). This may be either a folder path, in which case its contents are deleted, or a single file path, in which case only that file is deleted. If `remoteFolderPath` is an absolute path, the `commonRootAlias` in [WdDeleteOptions](/reference/remoting/structs/wddeleteoptions) is ignored.

`_In_opt_ deleteOptions`\
Type: **const [WdDeleteOptions](/reference/remoting/structs/wddeleteoptions)\***

Optional. Specifies the common root alias used for path resolution and whether removal of the root folder itself is attempted. Pass `nullptr` to use the default common root location when `remoteFolderPath` is a relative path, and to leave the root folder in place so that only its contents are deleted. When `remoteFolderPath` resolves to a single file, `deleteRootFolder` is ignored.

`_In_opt_ searchOptions`\
Type: **const [WdDeleteSearchOptions](/reference/remoting/structs/wddeletesearchoptions)\***

Optional. Specifies include/exclude patterns and attribute filters that select which files and directories are deleted. Pass `nullptr` to include all items. These options apply only when `remoteFolderPath` resolves to a folder; they are ignored when it resolves to a single file.

`_In_opt_ statusCallbacks`\
Type: **const [WdDeleteStatusCallbacks](/reference/remoting/structs/wddeletestatuscallbacks)\***

Currently ignored. Pass `nullptr`; no progress or error callbacks are invoked.

`_In_opt_ cancellationHandle`\
Type: **[WdCancellationHandle](/reference/remoting/structs/wdcancellationhandle)**

Optional. A cancellation handle created by [WdCreateCancellationHandle](/reference/remoting/functions/wdcreatecancellationhandle) that can be passed to [WdCancelRemoteDelete](/reference/remoting/functions/wdcancelremotedelete) from a separate thread to stop the client wait. Pass `nullptr` if cancellation is not needed.

### Return value

Type: **HRESULT**

Returns `S_OK` when the endpoint reports success or the client observes cancellation; otherwise, returns an error code. `S_OK` does not guarantee that every selected item was deleted. For the list of API-specific error codes, including root causes and troubleshooting guidance, see [XBOX PC Remote Iteration API Error Codes](/reference/remoting/error-codes).

## Remarks

`WdDeleteRemoteFiles` is a synchronous, blocking call. It waits for an endpoint result, an error, or observed cancellation via [WdCancelRemoteDelete](/reference/remoting/functions/wdcancelremotedelete). Deletion is best effort: no per-item results are returned, and file deletion failures are reported only in endpoint logs.

To enable cancellation, create a [WdCancellationHandle](/reference/remoting/structs/wdcancellationhandle) using [WdCreateCancellationHandle](/reference/remoting/functions/wdcreatecancellationhandle) before calling `WdDeleteRemoteFiles`, then pass it to [WdCancelRemoteDelete](/reference/remoting/functions/wdcancelremotedelete) from a separate thread. After `WdDeleteRemoteFiles` returns, close the handle with [WdCloseCancellationHandle](/reference/remoting/functions/wdclosecancellationhandle).

Cancellation stops the client wait, not deletion already started on the endpoint. When cancellation is observed, the call returns `S_OK` without confirming endpoint completion.

By default only the contents of `remoteFolderPath` are deleted and the folder itself is left in place. Set `deleteRootFolder` in [WdDeleteOptions](/reference/remoting/structs/wddeleteoptions) to `true` to also attempt to remove the folder once its contents have been deleted. Removal is best effort and is attempted only if the folder is left empty; a filtered delete that leaves items behind preserves the folder.

Regardless of `deleteRootFolder`, the operation also attempts to remove empty subdirectories that pass the directory filters, including directories that were already empty.

If `remoteFolderPath` is an absolute path, the `commonRootAlias` in [WdDeleteOptions](/reference/remoting/structs/wddeleteoptions) is ignored. If `remoteFolderPath` is a relative path, the default common root location is used unless a `commonRootAlias` is specified.

> \[!WARNING]
> Deletion can follow directory junctions and directory symbolic links beneath `remoteFolderPath` and delete matching files outside that directory. The operation can still return `S_OK`; no per-item results or undo operation are provided. Ensure the root is not itself a linked directory, and use `excludeDirPattern` to exclude known linked subdirectories by name.

## Examples

### Example 1: Clear a deployment folder

Attempts to delete the contents of a game folder on a remote device using default settings. The folder itself is left in place. A successful return does not prove that the folder is empty.

```cpp theme={null}
// BasicDelete.cpp
// Clears the contents of a deployment folder on a remote device.
// Build: Link against wdremoteapi.lib

#include <windows.h>
#include <stdio.h>
#include "WdRemoteIteration.h"

int main()
{
    // TODO: Replace with your remote device IP address or hostname
    const char* remoteDevice = "192.168.1.100";

    // TODO: Replace with the folder name on the remote device.
    // Relative paths resolve against the default common root.
    const char* remoteFolderPath = "MyGame";

    HRESULT hr = WdDeleteRemoteFiles(
        remoteDevice,
        remoteFolderPath,
        nullptr,    // deleteOptions — default common root, folder itself is kept
        nullptr,    // searchOptions - selects all items
        nullptr,    // statusCallbacks - currently ignored
        nullptr);   // cancellationHandle — no cancellation support

    if (SUCCEEDED(hr))
    {
        printf("Delete request completed. Some items may remain.\n");
    }
    else
    {
        printf("Delete failed: HRESULT 0x%08X\n", hr);
    }

    return hr;
}
```

### Example 2: Filtered delete

Attempts to remove selected build artifacts while preserving saved game data.

```cpp theme={null}
// FilteredDelete.cpp
// Deletes selected build artifacts.
// Build: Link against wdremoteapi.lib

#include <windows.h>
#include <stdio.h>
#include "WdRemoteIteration.h"

int main()
{
    const char* remoteDevice     = "192.168.1.100";
    const char* remoteFolderPath = "MyGame";

    // Remove executables and symbols, but keep save data
    WdDeleteSearchOptions searchOptions = {};
    searchOptions.includeFilePattern    = "*.exe;*.dll;*.pdb";
    searchOptions.excludeFilePattern    = "*.sav";
    searchOptions.excludeDirPattern     = "SaveData";
    searchOptions.includeFileAttributes = 0;  // No attribute-based include filter
    searchOptions.excludeFileAttributes = 0;  // No attribute-based exclude filter
    searchOptions.includeDirAttributes  = 0;  // No attribute-based include filter
    searchOptions.excludeDirAttributes  = 0;  // No attribute-based exclude filter

    HRESULT hr = WdDeleteRemoteFiles(
        remoteDevice,
        remoteFolderPath,
        nullptr,          // deleteOptions — defaults
        &searchOptions,
        nullptr,          // statusCallbacks - currently ignored
        nullptr);         // cancellationHandle — no cancellation support

    if (SUCCEEDED(hr))
    {
        printf("Delete request completed. Some items may remain.\n");
    }
    else
    {
        printf("Delete failed: HRESULT 0x%08X\n", hr);
    }

    return hr;
}
```

## Requirements

| Requirement | Value |
| - | - |
| **Header** | WdRemoteIteration.h |
| **Library** | wdremoteapi.lib |
| **Supported OS** | Windows 11 and later |
| **Supported architectures** | x64, ARM64 |

## See also

* [WdCancelRemoteDelete](/reference/remoting/functions/wdcancelremotedelete)
* [WdCancellationHandle](/reference/remoting/structs/wdcancellationhandle)
* [WdCreateCancellationHandle](/reference/remoting/functions/wdcreatecancellationhandle)
* [WdCloseCancellationHandle](/reference/remoting/functions/wdclosecancellationhandle)
* [WdDeleteOptions](/reference/remoting/structs/wddeleteoptions)
* [WdDeleteSearchOptions](/reference/remoting/structs/wddeletesearchoptions)
* [WdDeleteStatusCallbacks](/reference/remoting/structs/wddeletestatuscallbacks)
* [WdRemoteCopy](/reference/remoting/functions/wdremotecopy)
* [XBOX PC Remote Iteration API Error Codes](/reference/remoting/error-codes)
* [XBOX PC Remote Iteration API](/reference/remoting/remoteiteration_members)


## Related topics

- [WdCancelRemoteDelete](/reference/remoting/functions/wdcancelremotedelete.md)
- [WdDeleteFileProgressInfo](/reference/remoting/structs/wddeletefileprogressinfo.md)
- [WdDeleteOptions](/reference/remoting/structs/wddeleteoptions.md)
- [WdDeleteOperationSummary](/reference/remoting/structs/wddeleteoperationsummary.md)
- [WdDeleteProgressCallback](/reference/remoting/callbacks/wddeleteprogresscallback.md)
