UWP获得磁盘空间大小
在UWP环境中获得磁盘可用空间大小的教程一直没有,研究了几天我成功获得了相关数据。
很多开发win32程序的小伙伴喜欢使用**System.IO.DriveInfo.GetDrives()**,但是在UWP,这个只能获得盘符目录。
下面我介绍一下UWP获得磁盘可用空间大小的方法。
首先你需要一个指向根目录的StorageFolder对象,
我们要使用StorageFolder.Properties.RetrievePropertiesAsync()获得文件夹信息。
Namespace:
Windows.Storage.FileProperties
Assemblies:
Windows.Storage.FileProperties.dll, Windows.dll
C# 复制
1 public IAsyncOperation<IDictionary<string, object>> RetrievePropertiesAsync(IEnumerable<String> propertiesToRetrieve)
这里我们使用System.FreeSpace和System.Capacity获得空余空间和容量
1 | List<string> list = new List<string>(); |
可用的属性字符串
- System.ApplicationName
- System.Author
- System.Capacity
- System.Category
- System.Comment
- System.Company
- System.ComputerName
- System.ContainedItems
- System.ContentStatus
- System.ContentType
- System.Copyright
- System.DataObjectFormat
- System.DateAccessed
- System.DateAcquired
- System.DateArchived
- System.DateCompleted
- System.DateCreated
- System.DateImported
- System.DateModified
- System.DefaultSaveLocationIconDisplay
- System.DueDate
- System.EndDate
- System.FileAllocationSize
- System.FileAttributes
- System.FileCount
- System.FileDescription
- System.FileExtension
- System.FileFRN
- System.FileName
- System.FileOwner
- System.FileVersion
- System.FindData
- System.FlagColor
- System.FlagColorText
- System.FlagStatus
- System.FlagStatusText
- System.FreeSpace
- System.FullText
- System.Identity
- System.Identity.Blob
- System.Identity.DisplayName
- System.Identity.IsMeIdentity
- System.Identity.PrimaryEmailAddress
- System.Identity.ProviderID
- System.Identity.UniqueID
- System.Identity.UserName
- System.IdentityProvider.Name
- System.IdentityProvider.Picture
- System.ImageParsingName
- System.Importance
- System.ImportanceText
- System.IsAttachment
- System.IsDefaultNonOwnerSaveLocation
- System.IsDefaultSaveLocation
- System.IsDeleted
- System.IsEncrypted
- System.IsFlagged
- System.IsFlaggedComplete
- System.IsIncomplete
- System.IsLocationSupported
- System.IsPinnedToNameSpaceTree
- System.IsRead
- System.IsSearchOnlyItem
- System.IsSendToTarget
- System.IsShared
- System.ItemAuthors
- System.ItemClassType
- System.ItemDate
- System.ItemFolderNameDisplay
- System.ItemFolderPathDisplay
- System.ItemFolderPathDisplayNarrow
- System.ItemName
- System.ItemNameDisplay
- System.ItemNamePrefix
- System.ItemParticipants
- System.ItemPathDisplay
- System.ItemPathDisplayNarrow
- System.ItemType
- System.ItemTypeText
- System.ItemUrl
- System.Keywords
- System.Kind
- System.KindText
- System.Language
- System.LayoutPattern.ContentViewModeForBrowse
- System.LayoutPattern.ContentViewModeForSearch
- System.LibraryLocationsCount
- System.MileageInformation
- System.MIMEType
- System.Null
- System.OfflineAvailability
- System.OfflineStatus
- System.OriginalFileName
- System.OwnerSID
- System.ParentalRating
- System.ParentalRatingReason
- System.ParentalRatingsOrganization
- System.ParsingBindContext
- System.ParsingName
- System.ParsingPath
- System.PerceivedType
- System.PercentFull
- System.Priority
- System.PriorityText
- System.Project
- System.ProviderItemID
- System.Rating
- System.RatingText
- System.Sensitivity
- System.SensitivityText
- System.SFGAOFlags
- System.SharedWith
- System.ShareUserRating
- System.SharingStatus
- System.Shell.OmitFromView
- System.SimpleRating
- System.Size
- System.SoftwareUsed
- System.SourceItem
- System.StartDate
- System.Status
- System.StatusBarSelectedItemCount
- System.StatusBarViewItemCount
- System.Subject
- System.Thumbnail
- System.ThumbnailCacheId
- System.ThumbnailStream
- System.Title
- System.TotalFileSize
- System.Trademarks
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 idevlab's Blog!