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

屬性

例外狀況

指定的資料夾不存在。 檢查 路徑的值。

您沒有存取指定資料夾的許可權。 如需詳細資訊,請參閱 檔案存取權限

路徑不能是相對路徑或 URI。 檢查 路徑的值。

範例

下列範例示範如何藉由呼叫 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());
});

適用於

另請參閱