Jak spawdzić jaki rozmiar ma plik znając jego ścieżkę? (Delphi)
0
0
Google + "delphi file size" = http://delphi.about.com/od/delphitips2008/qt/filesize.htm
//The FileSize function returns the size of a file in bytes, -1 if the file was not found.
// returns file size in bytes or -1 if not found.
function FileSize(fileName : wideString) : Int64;
var
sr : TSearchRec;
begin
if FindFirst(fileName, faAnyFile, sr ) = 0 then
result := Int64(sr.FindData.nFileSizeHigh) shl Int64(32) + Int64(sr.FindData.nFileSizeLow)
else
result := -1;
FindClose(sr) ;
end;
0
Wersja z użyciem tylko WinAPI dla istniejącego pliku:
function SizeOfExistingFile(const FileName : string) : Int64;
var
FileHandle : THandle;
begin
FileHandle := CreateFile(PChar(FileName), GENERIC_READ,
FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
Result := GetFileSize(FileHandle, nil);
CloseHandle(FileHandle);
end;