Bagikan melalui


StorageFolder.GetFolderAsync(String) Metode

Definisi

Mendapatkan subfolder dengan nama yang ditentukan dari folder saat ini.

public:
 virtual IAsyncOperation<StorageFolder ^> ^ GetFolderAsync(Platform::String ^ name) = GetFolderAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<StorageFolder> GetFolderAsync(winrt::hstring const& name);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<StorageFolder> GetFolderAsync(string name);
function getFolderAsync(name)
Public Function GetFolderAsync (name As String) As IAsyncOperation(Of StorageFolder)

Parameter

name
String

Platform::String

winrt::hstring

Nama (atau jalur relatif terhadap folder saat ini) dari subfolder yang akan didapatkan.

Mengembalikan

Ketika metode ini berhasil diselesaikan, metode ini mengembalikan StorageFolder yang mewakili subfolder yang ditentukan.

Penerapan

M:Windows.Storage.IStorageFolder.GetFolderAsync(System.String) M:Windows.Storage.IStorageFolder.GetFolderAsync(Platform::String) M:Windows.Storage.IStorageFolder.GetFolderAsync(winrt::hstring)
Atribut

Pengecualian

Folder yang ditentukan tidak ada. Periksa nilai nama.

Anda tidak memiliki izin untuk mengakses folder yang ditentukan. Untuk informasi selengkapnya, lihat Izin akses file.

Jalur tidak dapat dalam format Uri (misalnya, /Aset). Periksa nilai nama.

Contoh

Contoh berikut menunjukkan cara mendapatkan subfolder dari folder saat ini dengan memanggil metode GetFolderAsync. Contoh ini juga menunjukkan cara mendapatkan subfolder dari subfolder folder saat ini dengan menyediakan jalur relatif.

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

// Get the app's local folder.
StorageFolder localFolder = ApplicationData.Current.LocalFolder;

// Create 2 levels of subfolders in the app's local folder.
string name1 = "Subfolder1";
StorageFolder subFolder1 = await localFolder.CreateFolderAsync(name1);
string name2 = "Subfolder2";
StorageFolder subFolder2 = await subFolder1.CreateFolderAsync(name2);

// Get the subfolder of the app's local folder.
string level1FolderName = "Subfolder1";
StorageFolder level1Folder = await localFolder.GetFolderAsync(level1FolderName);

// Get the subfolder of the subfolder by providing a relative path.
string level2FolderName = @"Subfolder1\Subfolder2";
StorageFolder level2Folder = await localFolder.GetFolderAsync(level2FolderName);
IAsyncAction MainPage::ExampleCoroutineAsync()
{
    // Get the app's local folder.
    Windows::Storage::StorageFolder localFolder{ Windows::Storage::ApplicationData::Current().LocalFolder() };

    // Create two levels of subfolders in the app's local folder.
    std::wstring name1{ L"Subfolder1" };
    std::wstring name2{ L"Subfolder2" };
    std::wstring level2FolderName{ L"Subfolder1\\Subfolder2" };

    Windows::Storage::StorageFolder subFolder1{ co_await localFolder.CreateFolderAsync(name1) };
    Windows::Storage::StorageFolder subFolder2{ co_await subFolder1.CreateFolderAsync(name2) };
    // Get the subfolder of the subfolder by providing a relative path.
    Windows::Storage::StorageFolder level2FolderFromRelativePath{ co_await localFolder.GetFolderAsync(level2FolderName) };
}
// Get the app's local folder
StorageFolder^ localFolder = ApplicationData::Current->LocalFolder;

// Create 2 levels of subfolders in the app's local folder.
String^ name1 = "Subfolder1";
String^ name2 = "Subfolder2";
String^ level2FolderName = "Subfolder1\\Subfolder2";

create_task(localFolder->CreateFolderAsync(name1)).then([=](StorageFolder^ subFolder1) -> task <StorageFolder^> {
 return create_task(subFolder1->CreateFolderAsync(name2));
}).then([=](StorageFolder^ subFolder2) -> task<StorageFolder^> {
 // Get the subfolder of the subfolder
 // by providing a relative path.
 return create_task(localFolder->GetFolderAsync(level2FolderName));
});

Berlaku untuk

Lihat juga