Powershell returns 与实际文件大小不同

Powershell returns a different Filesize from Actual

Powershell 在使用 file.Length 命令查询 mp4 文件时返回不同的文件大小(46)

实际文件大小为 32029227 .

也尝试使用 Get-ItemGet-ItemPropertyValue 但是 Powershell 找不到该文件,尽管它显然存在。

为什么会出现这种差异?

***Console***  

    PS C:\Users\User0\Desktop\kcg_transcode> dir

    Directory: C:\Users\User0\Desktop\kcg_transcode

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       19-08-2020     15:59       32029227 Produce.mp4


PS C:\Users\User0\Desktop\kcg_transcode> $pd_output = 'C:\Users\User0\Desktop\kcg_convert\Produce.mp4'.Length

PS C:\Users\User0\Desktop\kcg_transcode> $pd_output

46  



 PS C:\Users\User0\Desktop\kcg_transcode> $pd_output = (Get-Item 'C:\Users\User0\Desktop\kcg_convert\Produce.mp4').Length

Get-Item : Cannot find path 'C:\Users\User0\Desktop\kcg_convert\Produce.mp4' because it does not exist.
At line:1 char:15
+ ... d_output = (Get-Item 'C:\Users\User0\Desktop\kcg_convert\Produce.mp4' ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\User0\...ert\Produce.mp4:String) [Get-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand
     


PS C:\Users\User0\Desktop\kcg_transcode> Get-ItemPropertyValue 'C:\Users\User0\Desktop\kcg_convert\Produce.mp4' -Name Length 

Get-ItemPropertyValue : Cannot find path 'C:\Users\User0\Desktop\kcg_convert\Produce.mp4' because it does not exist.
At line:1 char:1
+ Get-ItemPropertyValue 'C:\Users\User0\Desktop\kcg_convert\Produce.mp4 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\User0\...ert\Produce.mp4:String) [Get-ItemPropertyValue], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyValueCommand

Powershell 在下面的命令中返回字符串值而不是实际文件大小 -

 $pd_output = 'C:\Users\User0\Desktop\kcg_convert\Produce.mp4'.Length

在 Get-Item 和 Get-ItemPropertyValue 中缺少 -Path 标志。提供此标志后,将返回正确的文件大小。

 $pd_output = (Get-Item -Path 'C:\Users\User0\Desktop\kcg_convert\Produce.mp4').Length  

 $pd_output = Get-ItemPropertyValue -Path 'C:\Users\User0\Desktop\kcg_convert\Produce.mp4'  -Name Length