StorageFolder.GetFolderFromPathAsync(String) メソッド

定義

ファイル システム内の指定した絶対パスを持つフォルダーを取得します。

public:
 static IAsyncOperation<StorageFolder ^> ^ GetFolderFromPathAsync(Platform::String ^ path);
/// [Windows.Foundation.Metadata.RemoteAsync]
 static IAsyncOperation<StorageFolder> GetFolderFromPathAsync(winrt::hstring const& path);
[Windows.Foundation.Metadata.RemoteAsync]
public static IAsyncOperation<StorageFolder> GetFolderFromPathAsync(string path);
function getFolderFromPathAsync(path)
Public Shared Function GetFolderFromPathAsync (path As String) As IAsyncOperation(Of StorageFolder)

パラメーター

path
String

Platform::String

winrt::hstring

取得するフォルダーの (Uri ではなく) ファイル システム内の絶対パス。

パスでスラッシュを使用する場合は、必ず円記号 (\) を使用してください。 スラッシュ (/) は、このメソッドでは受け入れられません。

戻り値

このメソッドが正常に完了すると、指定したフォルダーを表す StorageFolder が返されます。

属性

例外

指定したフォルダーが存在しません。 path の値を確認 します

指定したフォルダーにアクセスするためのアクセス許可がありません。 詳細については、「 ファイル アクセス許可」を参照してください。

パスを相対パスまたは Uri にすることはできません。 path の値を確認 します

次の例では、GetFolderFromPathAsync メソッドを呼び出して、ファイル システムで指定された絶対パスを持つフォルダーを取得する方法を示します。

using Windows.Storage;
using System.Threading.Tasks;

// Get the path to the app's Assets folder.
string root = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;
string path = root + @"\Assets";

// Get the folder object that corresponds to this absolute path in the file system.
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(path);
IAsyncAction MainPage::ExampleCoroutineAsync()
{
    // Get the path to the app's Assets folder.
    std::wstring path{ Windows::ApplicationModel::Package::Current().InstalledLocation().Path() + L"\\Assets" };

    // Get the folder object that corresponds to this absolute path in the file system.
    Windows::Storage::StorageFolder folder{ co_await Windows::Storage::StorageFolder::GetFolderFromPathAsync(path) };
    ::OutputDebugString(folder.Name().c_str());
}
// Get the path to the app's installation folder.
String^ root = Windows::ApplicationModel::Package::Current->InstalledLocation->Path;

// Get the folder object that corresponds to
// this absolute path in the file system.
create_task(StorageFolder::GetFolderFromPathAsync(root)).then([=](StorageFolder^ folder){
 String^ output = folder->Name;
 OutputDebugString(output->Begin());
});

適用対象

こちらもご覧ください