Сценарий PowerShell для получения общего размера каталога

Как априори максимум и минимум не уникальны, вы можете играть из

import pandas as pd
import numpy as np

df = pd.DataFrame(np.arange(6).reshape(2,3))

#show max
df[df==df.max().max()]

#show min
df[df==df.min().min()]
17
задан Peter Mortensen 11 January 2010 в 21:01
поделиться

2 ответа

Try the following

function Get-DirectorySize() {
  param ([string]$root = $(resolve-path .))
  gci -re $root |
    ?{ -not $_.PSIsContainer } | 
    measure-object -sum -property Length
}

This actually produces a bit of a summary object which will include the Count of items. You can just grab the Sum property though and that will be the sum of the lengths

$sum = (Get-DirectorySize "Some\File\Path").Sum

EDIT Why does this work?

Let's break it down by components of the pipeline. The gci -re $root command will get all items from the starting $root directory recursively and then push them into the pipeline. So every single file and directory under the $root will pass through the second expression ?{ -not $_.PSIsContainer }. Each file / directory when passed to this expression can be accessed through the variable $_. The preceding ? indicates this is a filter expression meaning keep only values in the pipeline which meet this condition. The PSIsContainer method will return true for directories. So in effect the filter expression is only keeping files values. The final cmdlet measure-object will sum the value of the property Length on all values remaining in the pipeline. So it's essentially calling Fileinfo.Length for all files under the current directory (recursively) and summing the values.

23
ответ дан 30 November 2019 в 12:36
поделиться

Если вас интересует включение размера скрытых и системных файлов, вам следует использовать параметр -force с Get-ChildItem.

3
ответ дан 30 November 2019 в 12:36
поделиться
Другие вопросы по тегам:

Похожие вопросы: