> ## 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

リモート デバイス上のファイルとディレクトリをベスト エフォートで削除します。

**導入バージョン:** [RIT 0.0.13-preview](/ja-jp/reference/remoting/release-versions#release-versions)。

## 構文

```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  
);  
```

### パラメーター

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

リモート デバイスのアドレスまたは名前 (UTF-8)。たとえば `"192.168.1.100"` や `"MyDevKit"` です。

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

削除するリモート デバイス上のパス (UTF-8)。フォルダー パスを指定した場合はその内容が削除され、単一のファイル パスを指定した場合はそのファイルのみが削除されます。`remoteFolderPath` が絶対パスの場合、[WdDeleteOptions](/ja-jp/reference/remoting/structs/wddeleteoptions) の `commonRootAlias` は無視されます。

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

省略可能。パスの解決に使用する共通ルート エイリアスと、ルート フォルダー自体の削除を試みるかどうかを指定します。`remoteFolderPath` が相対パスの場合に既定の共通ルートの場所を使用し、ルート フォルダーをそのまま残してその内容のみを削除するには、`nullptr` を渡します。`remoteFolderPath` が単一のファイルに解決される場合、`deleteRootFolder` は無視されます。

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

省略可能。削除するファイルとディレクトリを選択するための包含/除外パターンと属性フィルターを指定します。すべての項目を対象にするには `nullptr` を渡します。これらのオプションは、`remoteFolderPath` がフォルダーに解決される場合にのみ適用され、単一のファイルに解決される場合は無視されます。

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

現在は無視されます。`nullptr` を渡してください。進行状況コールバックやエラー コールバックは呼び出されません。

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

省略可能。[WdCreateCancellationHandle](/ja-jp/reference/remoting/functions/wdcreatecancellationhandle) で作成したキャンセル ハンドル。別のスレッドから [WdCancelRemoteDelete](/ja-jp/reference/remoting/functions/wdcancelremotedelete) に渡して、クライアントの待機を停止できます。キャンセルが不要な場合は `nullptr` を渡します。

### 戻り値

Type: **HRESULT**

エンドポイントが成功を報告した場合、またはクライアントがキャンセルを検知した場合は `S_OK` を返します。それ以外の場合はエラー コードを返します。`S_OK` は、選択されたすべての項目が削除されたことを保証するものではありません。根本原因やトラブルシューティングのガイダンスを含む API 固有のエラー コードの一覧については、「[XBOX PC Remote Iteration API のエラー コード](/ja-jp/reference/remoting/error-codes)」を参照してください。

## 解説

`WdDeleteRemoteFiles` は同期のブロッキング呼び出しです。エンドポイントの結果、エラー、または [WdCancelRemoteDelete](/ja-jp/reference/remoting/functions/wdcancelremotedelete) によるキャンセルの検知を待機します。削除はベスト エフォートで行われます。項目ごとの結果は返されず、ファイル削除の失敗はエンドポイントのログにのみ報告されます。

キャンセルを有効にするには、`WdDeleteRemoteFiles` を呼び出す前に [WdCreateCancellationHandle](/ja-jp/reference/remoting/functions/wdcreatecancellationhandle) を使用して [WdCancellationHandle](/ja-jp/reference/remoting/structs/wdcancellationhandle) を作成し、別のスレッドからそれを [WdCancelRemoteDelete](/ja-jp/reference/remoting/functions/wdcancelremotedelete) に渡します。`WdDeleteRemoteFiles` から制御が戻った後、[WdCloseCancellationHandle](/ja-jp/reference/remoting/functions/wdclosecancellationhandle) でハンドルを閉じます。

キャンセルによって停止されるのはクライアントの待機であり、エンドポイントで既に開始された削除ではありません。キャンセルが検知されると、この呼び出しはエンドポイントでの完了を確認せずに `S_OK` を返します。

既定では、`remoteFolderPath` の内容のみが削除され、フォルダー自体はそのまま残ります。内容の削除後にフォルダー自体の削除も試みるには、[WdDeleteOptions](/ja-jp/reference/remoting/structs/wddeleteoptions) の `deleteRootFolder` を `true` に設定します。フォルダーの削除はベスト エフォートで行われ、フォルダーが空になった場合にのみ試行されます。フィルター処理された削除によって項目が残った場合、フォルダーは保持されます。

`deleteRootFolder` の設定にかかわらず、この操作では、ディレクトリ フィルターを通過した空のサブディレクトリ (元から空だったディレクトリを含む) の削除も試みます。

`remoteFolderPath` が絶対パスの場合、[WdDeleteOptions](/ja-jp/reference/remoting/structs/wddeleteoptions) の `commonRootAlias` は無視されます。`remoteFolderPath` が相対パスの場合、`commonRootAlias` が指定されていない限り、既定の共通ルートの場所が使用されます。

> \[!WARNING]
> 削除処理は `remoteFolderPath` の下にあるディレクトリ ジャンクションやディレクトリ シンボリック リンクをたどり、そのディレクトリの外部にある一致するファイルを削除する可能性があります。その場合でも、操作は `S_OK` を返すことがあります。項目ごとの結果や元に戻す操作は提供されません。ルート自体がリンクされたディレクトリでないことを確認し、既知のリンクされたサブディレクトリを名前で除外するには `excludeDirPattern` を使用してください。

## 例

### 例 1: 展開フォルダーをクリアする

既定の設定を使用して、リモート デバイス上のゲーム フォルダーの内容の削除を試みます。フォルダー自体はそのまま残ります。正常に戻った場合でも、フォルダーが空であることは保証されません。

```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;
}
```

### 例 2: フィルター処理された削除

保存されたゲーム データを保持しながら、選択したビルド成果物の削除を試みます。

```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;
}
```

## 要件

| 要件 | 値 |
| - | - |
| **ヘッダー** | WdRemoteIteration.h |
| **ライブラリ** | wdremoteapi.lib |
| **サポートされている OS** | Windows 11 以降 |
| **サポートされているアーキテクチャ** | x64、ARM64 |

## 関連項目

* [WdCancelRemoteDelete](/ja-jp/reference/remoting/functions/wdcancelremotedelete)
* [WdCancellationHandle](/ja-jp/reference/remoting/structs/wdcancellationhandle)
* [WdCreateCancellationHandle](/ja-jp/reference/remoting/functions/wdcreatecancellationhandle)
* [WdCloseCancellationHandle](/ja-jp/reference/remoting/functions/wdclosecancellationhandle)
* [WdDeleteOptions](/ja-jp/reference/remoting/structs/wddeleteoptions)
* [WdDeleteSearchOptions](/ja-jp/reference/remoting/structs/wddeletesearchoptions)
* [WdDeleteStatusCallbacks](/ja-jp/reference/remoting/structs/wddeletestatuscallbacks)
* [WdRemoteCopy](/ja-jp/reference/remoting/functions/wdremotecopy)
* [XBOX PC Remote Iteration API のエラー コード](/ja-jp/reference/remoting/error-codes)
* [XBOX PC Remote Iteration API](/ja-jp/reference/remoting/remoteiteration_members)


## Related topics

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