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());
});

适用于

另请参阅