StorageFolder.GetFolderFromPathAsync(String) Método

Definição

Obtém a pasta que tem o caminho absoluto especificado no sistema de arquivos.

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)

Parâmetros

path
String

Platform::String

winrt::hstring

O caminho absoluto no sistema de arquivos (não o URI) da pasta a ser obtido.

Se o caminho usar barras, certifique-se de usar barras invertidas (\). As barras (/) não são aceitas por esse método.

Retornos

Quando esse método for concluído com êxito, ele retornará uma StorageFolder que representa a pasta especificada.

Atributos

Exceções

A pasta especificada não existe. Verifique o valor do caminho.

Você não tem permissão para acessar a pasta especificada. Para obter mais informações, consulte Permissões de acesso a arquivos.

O caminho não pode ser um caminho relativo ou um URI. Verifique o valor do caminho.

Exemplos

O exemplo a seguir mostra como obter a pasta que tem o caminho absoluto especificado no sistema de arquivos chamando o método 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());
});

Aplica-se a

Confira também