检查 StorageFolder 指向的文件夹是否仍然存在

Check if folder pointed by StorageFolder still exist

如何检查 StorageFolder 指向的文件夹是否仍然存在?

假设您的应用具有 ,您可以使用 StorageFolder.GetFolderFromPathAsync API。

以下示例代码是用 C# 编写的,但应该能让您明白:

public static async Task<bool> ExistsAsync(StorageFolder folder)
{
    try
    {
        await StorageFolder.GetFolderFromPathAsync(folder.Path);
        return true;
    }
    catch (FileNotFoundException)
    {
        return false;
    }
}