2017-01-16 15 views
1

ディレクトリのサイズを返す関数を作成しようとしています。私は次のコードを書いたが、正しいサイズを返していない。たとえば、{pf}ディレクトリで実行すると、174バイトが返されます。このディレクトリは複数のギガバイトであるため、間違っています。ここで私が持っているコードは次のとおりです。Inno Setupサブディレクトリを含むディレクトリサイズを取得する

function GetDirSize(DirName: String): Int64; 
var 
    FindRec: TFindRec; 
begin 
    if FindFirst(DirName + '\*', FindRec) then 
    begin 
     try 
     repeat 
      Result := Result + (Int64(FindRec.SizeHigh) shl 32 + FindRec.SizeLow); 
     until not FindNext(FindRec); 
     finally 
     FindClose(FindRec); 
     end; 
    end 
    else 
    begin 
     Result := -1; 
    end; 
end; 

私はFindFirst機能は、私が正しい結果を取得していない午前理由である、サブディレクトリが含まれていないと思われます。したがって、どのようにして正しいサイズのディレクトリ、つまりすべてのサブディレクトリにあるすべてのファイルを返すことができますか?Windowsエクスプローラでフォルダのプロパティを選択するのと同じですか?私はFindFirstを使用しています。機能は2GBを超えるディレクトリサイズをサポートする必要があるためです。

答えて

1

FindFirstにはサブディレクトリが含まれていますが、サイズは取得できません。

Inno Setup: copy folder, subfolders and files recursively in Code sectionの場合と同様に、サブディレクトリに再帰的に移動し、ファイルごとに合計サイズを計算する必要があります。 Int64については

function GetDirSize(Path: String): Int64; 
var 
    FindRec: TFindRec; 
    FilePath: string; 
    Size: Int64; 
begin 
    if FindFirst(Path + '\*', FindRec) then 
    begin 
    Result := 0; 
    try 
     repeat 
     if (FindRec.Name <> '.') and (FindRec.Name <> '..') then 
     begin 
      FilePath := Path + '\' + FindRec.Name; 
      if (FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY) <> 0 then 
      begin 
      Size := GetDirSize(FilePath); 
      end 
      else 
      begin 
      Size := Int64(FindRec.SizeHigh) shl 32 + FindRec.SizeLow; 
      end; 
      Result := Result + Size; 
     end; 
     until not FindNext(FindRec); 
    finally 
     FindClose(FindRec); 
    end; 
    end 
    else 
    begin 
    Log(Format('Failed to list %s', [Path])); 
    Result := -1; 
    end; 
end; 

、あなたはどのような場合に使用すべきか、Unicode version of Inno Setupを必要としています。 Ansiバージョンを使用する理由がある場合にのみ、Int64Integerに置き換えることができますが、2GBに制限されています。

+0

私はバージョン2.2で、Int64は認識できません。どのような選択肢が使えますか? – Brian

+0

@Brianバージョン2.2の何ですか? –

+0

2.2 inno setup studio – Brian

関連する問題