AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Bytes einer Datei berechnen

Ein Thema von HW764 · begonnen am 7. Sep 2004 · letzter Beitrag vom 7. Sep 2004
Antwort Antwort
HW764
(Gast)

n/a Beiträge
 
#1

Bytes einer Datei berechnen

  Alt 7. Sep 2004, 20:04
Wie bringe ich delphi dazu, dass er:

1.Den Pfad aus einer Datei aus Edit1 ausliest
2.Er sie Grösse der in edit1 stehenden Datei erkennt
3.Er sie in bytes umrechnet und halbiert. (und auf die Grössere bytezahl rundet)

Gruss HW764
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#2

Re: Bytes einer Datei berechnen

  Alt 7. Sep 2004, 20:08
1. Grundlagen:
Delphi-Quellcode:
var
  s: String;
begin
  s := Edit1,text;
2. Forensuche sollte helfen.

3. Grundlagen: Grundrechenarten in Delphi.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Benutzerbild von Nothine
Nothine

Registriert seit: 3. Jul 2004
Ort: Mülheim an der Ruhr
198 Beiträge
 
Delphi 5 Enterprise
 
#3

Re: Bytes einer Datei berechnen

  Alt 7. Sep 2004, 20:28
Zitat von HW764:
1.Den Pfad aus einer Datei aus Edit1 ausliest
Delphi-Quellcode:
var F: File;

...

begin
  AssignFile(F,Edit1.Text);
  Reset(F);
end;
{ Hinterher mit
  CloseFile(F);
  wieder freigeben}
Zitat von HW764:
2.Er sie Grösse der in edit1 stehenden Datei erkennt
  DeineVariable := FileSize(F); //in Byte
Zitat von HW764:
3.Er sie in bytes umrechnet und halbiert. (und auf die Grössere bytezahl rundet)
das wird durch FileSize bereits erledigt...
if ThisPost is senseless then
ThisPost.WasPostedBy := SomeoneElse();
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#4

Re: Bytes einer Datei berechnen

  Alt 7. Sep 2004, 20:33
Man beachte:
Zitat:
Description

Call FileSize to determine the size of the file specified by the file variable F. The size is expressed as the number of records in a record file. Thus:

If the file is declared as a file of byte, then the record size defaults to one byte, and FileSize returns the number of bytes in the file.
The Reset procedure can set the record size (in bytes) when it opens the file. In this case, FileSize returns the number of records in the file.

Note: If the file is declared as an untyped file and you don’t specify a record size when you call Reset, then FileSize assumes a record size of 128. That is, FileSize gives the number of bytes divided by 128.

To use FileSize, the file must be open. If the file is empty, FileSize(F) returns 0.

Note: FileSize can't be used on a text file.
So würde ich es machen:
Delphi-Quellcode:
function GetFileSize(szFile: PChar): Int64;
var
  fFile: THandle;
  wfd: TWIN32FINDDATA;
begin
  result := 0;
  if not FileExists(szFile) then exit;
  fFile := FindFirstfile(pchar(szFile),wfd);
  if fFile = INVALID_HANDLE_VALUE then exit;
  result := (wfd.nFileSizeHigh*(Int64(MAXDWORD) + 1))+wfd.nFileSizeLow;
  windows.FindClose(fFile);
end;
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Benutzerbild von mirage228
mirage228

Registriert seit: 23. Mär 2003
Ort: Münster
3.750 Beiträge
 
Delphi 2010 Professional
 
#5

Re: Bytes einer Datei berechnen

  Alt 7. Sep 2004, 20:35
Ich stelle jetzt mal einfach so meine Funktion in den Raum
Delphi-Quellcode:
  function GetFileSize(const FileName: String; var Size: Int64): Boolean;
  var
    sr: TWin32FindData;
    h: HWND;
  begin
    h := FindFirstFile(PChar(FileName), sr);
    Result := (h <> 0) and (FileExists(FileName)) and (sr.dwFileAttributes and
       FILE_ATTRIBUTE_DIRECTORY = 0);
    if Result then
      Size := (sr.nFileSizeHigh * MAXDWORD) + sr.nFileSizeLow else Size := 0;
    Windows.FindClose(h);
  end;
mfG
mirage228
David F.

May the source be with you, stranger.
PHP Inspection Unit (Delphi-Unit zum Analysieren von PHP Code)
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:37 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz