Bagikan melalui


StorageFolder.GetFolderFromPathAsync(String) Metode

Definisi

Mendapatkan folder yang memiliki jalur absolut yang ditentukan dalam sistem file.

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)

Parameter

path
String

Platform::String

winrt::hstring

Jalur absolut dalam sistem file (bukan Uri) dari folder yang akan didapatkan.

Jika jalur Anda menggunakan garis miring, pastikan Anda menggunakan garis miring terbelakang (\). Garis miring (/) tidak diterima oleh metode ini.

Mengembalikan

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

Atribut

Pengecualian

Folder yang ditentukan tidak ada. Periksa nilai jalur.

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

Jalur tidak boleh berupa jalur relatif atau Uri. Periksa nilai jalur.

Contoh

Contoh berikut menunjukkan cara mendapatkan folder yang memiliki jalur absolut yang ditentukan dalam sistem file dengan memanggil metode 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());
});

Berlaku untuk

Lihat juga