簡體   English   中英

如何在存儲設備上獲取可用空間

[英]How to get available space on Storage Device

我正在使用Windows Store應用程序(Windows 8.1,使用VS2012),但無法從特定的Storage Folder檢索可用/已使用的空間,該文件夾是從存儲設備中檢索到的。 需要明確的是,該應用程序旨在在桌面上運行,並通過存儲設備API與與其連接的USB設備交換文件。

這是我到目前為止所擁有的:

StorageFolder folder = Windows.Devices.Portable.StorageDevice.FromId(phoneId);

UInt64[] info = new UInt64[] {};
var properties = await folder.Properties.RetrievePropertiesAsync(
    new string[] { "System.FreeSpace", "System.Capacity" });

if (properties.ContainsKey("System.FreeSpace") && properties.ContainsKey("System.FreeSpace"))
{
  info = new UInt64[] {
    (UInt64) properties["System.FreeSpace"],
    (UInt64) properties["System.Capacity"]
  };
}
return info;

但是沒有成功,“信息”始終是一個空數組。 有任何想法嗎?

我發現自己在做什么錯。 我的StorageFolder對象代表連接到桌面的電話。 如果通過瀏覽器訪問“電話”文件夾,將看到其“內部文件夾”,這是電話中的實際存儲文件夾(例如,內部存儲,SD卡等)。

用手機執行此操作的正確方法是訪問子文件夾(即每個內部存儲器)。 我現在使用的代碼:

StorageFolder folder = Windows.Devices.Portable.StorageDevice.FromId(phoneId);

var data = new List<Tuple<string, UInt64[]>> { };
IReadOnlyList<StorageFolder> subFolders = await folder.GetFoldersAsync();
foreach (StorageFolder subFolder in subFolders)
{
  var props = await subFolder.Properties.RetrievePropertiesAsync(
    new string[] { "System.FreeSpace", "System.Capacity" });
  if (props.ContainsKey("System.FreeSpace") && props.ContainsKey("System.Capacity"))
  {
    data.Add(Tuple.Create(
      subFolder.Name,
      new UInt64[] {
        (UInt64) props["System.FreeSpace"],
        (UInt64) props["System.Capacity"]
    }));
  }
}
return data;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM