delphi中获得文件或文件夹大小的函数(国外英文资料).doc
文本预览下载声明
delphi中获得文件或文件夹大小的函数(国外英文资料)
How do I get the file size in Delphi?
There are probably these methods for obtaining file sizes
FileSizeByName (referring to IdGlobal units)
GetFileSize
FileSize (not the size of the file being used)
FileSeek
TFileStream. Size
Here is the use case
1. FileSizeByName (referring to IdGlobal units)
The begin
If opendialog1.execute then
The begin
(FileSizeByName (opendialog1.filename));
The end;
2. GetFileSize
var
FileHandle: integer;
The begin
If opendialog1.execute then
The begin
FileHandle: = FileOpen (opendialog1.filename, 0)
(GetFileSize (FileHandle, nil));
FileClose (FileHandle);
The end;
3. FileSize (not the size of the file being used)
Var f: file;
The begin
If opendialog1.execute then
The begin
AssignFile (f, opendialog1.filename);
Reset (f, 1);
(FileSize (f));
CloseFile (f);
The end;
4. FileSeek
var
FileHandle: integer;
The begin
If opendialog1.execute then
The begin
FileHandle: = FileOpen (opendialog1.filename, 0)
(FileSeek (FileHandle, 0, 2))
FileClose (FileHandle);
The end;
5. TFileStream. Size
var
FS: TFileStream;
The begin
If opendialog1.execute then
The begin
FS: = tfilestream.create (opendialog1.filename, fmShareDenyNone);
ShowMessage (IntToStr (s.size));
FS. Free;
The end;
There is also a function of FileSizeByName () in IdGlobalProtocols.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Use Delphi to obtain a folder size of the 2008-07-12 22:57 using the following function, it USES a recursive algorithm to find all the attributes of files (including hidden, system, archive, etc.) in this folder and subfolders.
Simply use a folder path as a parameter.
It looks at hidden, system, archive, and normal files; it USES a recursive algorithm to look in all sub-directories as a parameter.
reference
var
DirBytes: integer;
Function FolderSize (Dir: string) : integer;
var
SearchRec: TSearchRec;
The Separator, the string;
T
显示全部