Autor Beitrag
P@u1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 117



BeitragVerfasst: Do 11.03.10 17:30 
Hi,

gibt es eine gute Möglichkeit, die Größe einer Datei rauszufinden? Die Anwendung für die ich das verwenden will, soll die Größe von sich selbst bestimmen.

Bitte jetzt nicht einfach sagen, dass es keinen Grund dafür gibt, ich möchte wissen ob und wenn ja, wie das geht.

Vielen Dank
DonManfred
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 148
Erhaltene Danke: 2

Windows 7
Delphi XE3 Pro + HTML5Builder
BeitragVerfasst: Do 11.03.10 17:37 
Ich schmeiss mal ein FileSize(f) in den Raum...

ausblenden Delphi-Quelltext
1:
2:
3:
    AssignFile(f, OpenDialog1.FileName);
    Reset(f);
    size := FileSize(f);

_________________
Gruss Manfred


Zuletzt bearbeitet von DonManfred am Do 11.03.10 17:38, insgesamt 1-mal bearbeitet
P@u1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 117



BeitragVerfasst: Do 11.03.10 17:39 
danke, habs hinbekommen
Ironwulf
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: So 11.07.10 13:20 
das scheint nicht mit datein > 2gb zu funktionieren, gibt es dafür eine möglichkeit?
z.b. hab ich bei ner 8gb datei das ergebnis: -62539274
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 11.07.10 13:25 
Das geht z.B. mit GetFileSize bzw. besser GetFileSizeEx.
Ironwulf
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: So 11.07.10 14:16 
thx funktioniert
Ironwulf
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: So 11.07.10 14:40 
doch nicht so recht das funktioniert nur bis 4gb...
gibts da noch was anderes?
dummzeuch
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 593
Erhaltene Danke: 5


Delphi 5 ent, Delphi 6 bis Delphi XE8 pro
BeitragVerfasst: So 11.07.10 15:05 
user profile iconDonManfred hat folgendes geschrieben Zum zitierten Posting springen:
Ich schmeiss mal ein FileSize(f) in den Raum...

ausblenden Delphi-Quelltext
1:
2:
3:
    AssignFile(f, OpenDialog1.FileName);
    Reset(f);
    size := FileSize(f);


Ist das Reset wirklich noetig? Wenn ja, fehlt noch ein FileClose.

twm
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: So 11.07.10 17:24 
user profile iconIronwulf hat folgendes geschrieben Zum zitierten Posting springen:
doch nicht so recht das funktioniert nur bis 4gb...
gibts da noch was anderes?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
function GetFileSize(Filename: String): Int64;
var Stream: TFileStream;
begin
  result := 0;
  Stream := TFileStream.Create(Filename, fmOpenRead);
  try
    result := Stream.Size;
  finally
    Stream.Free;
  end;
end;

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 11.07.10 20:54 
Oder so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
function GetFileSize(AFilename: string): Int64;
const
  SEEK_END = 2;
var
  FileHandle: THandle;
begin
  Result := 0;
  FileHandle := CreateFile(PChar(AFilename), GENERIC_READ, FILE_SHARE_READ, nil,
    OPEN_EXISTING, 00);
  if FileHandle <> INVALID_HANDLE_VALUE then
  begin
    Int64Rec(Result).Lo := SetFilePointer(FileHandle, 0,
      @Int64Rec(Result).Hi, SEEK_END);
    if (Int64Rec(Result).Lo = $FFFFFFFFand (GetLastError <> 0then
      Int64Rec(Result).Hi := $FFFFFFFF;
    CloseHandle(FileHandle);
  end;
end;
Laut Doku von SetFilePointer muss man GetLastError prüfen um festzustellen, ob es sich um einen Fehlerwert oder einen gültigen Wert handelt. Getestet habe ich den Fall nicht.
Gerd Kayser
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 632
Erhaltene Danke: 121

Win 7 32-bit
Delphi 2006/XE
BeitragVerfasst: Di 13.07.10 11:51 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
var
  Search : TSearchRec;
begin
  if FindFirst('L:\Test.rar', faAnyFile, Search) = 0 then
    Label1.Caption := IntToStr(Search.Size);
  SysUtils.FindClose(Search);
end;
Funktioniert auch bei Dateien größer 4 GB.