如何在WinRT中获取文件大小

本文关键字:获取 文件大小 WinRT | 更新日期: 2023-09-27 17:50:41

在WinRT中没有FileInfo类,只有StorageFile类。

如何使用StorageFile类获得文件的大小?

如何在WinRT中获取文件大小

就是这样


storageFile.getBasicPropertiesAsync().then(
    function (basicProperties) {
        var size  = basicProperties.size;
    }
);

在c#中:

StorageFile file = await openPicker.PickSingleFileAsync();
BasicProperties pro = await file.GetBasicPropertiesAsync();
if (pro.Size != 0){}

你应该使用Windows.Storage.FileProperties作为基本属性。

你试过了吗:

<>之前create_task(文件-> GetBasicPropertiesAsync())。然后([this, file](BasicProperties^ BasicProperties){String^ dateModifiedString = dateFormat->Format(basicProperties->DateModified) + " " + timeFormat->Format(basicProperties->DateModified);OutputTextBlock->Text += "'nFile size: " + basicProperties-> size . tostring () + " bytes" + "'nDate modified: " + dateModifiedString;});之前

看:http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.fileproperties.basicproperties.size.aspx