Delphi Check File Size

Use Size to find the size of the stream. Size is used internally in routines that read and write to and from the stream. Setting the Size property of TStream does nothing. Some descendants of TStream override this property to allow applications to change the size of the resource accessed using the stream. C++ Examples. In short, a Delphi project is just a collection of files that make up an application created by Delphi. DPR is the file extension used for the Delphi Project file format to store all the files related to the project. This includes other Delphi file types like Form files (DFMs) and Unit Source files (.PASs).

  • How to check in bash if file size is greater than N. Shell find bash. You can do this using the find command and the. (find /path/to/file -type f -size +51200c 2>/dev/null) ]]; then somecmd fi. Written by Janos Gyerik. Respond 3 Responses Add your response. November 09, 2014 14:28.
  • Delphi how to know the size of a file at server side using Thttpcli Is here any one familar with Thtttpcli(component).How to use it to get the size of a file at server side before download?
  • Else ShowMessage('File is not archived'); if attrs and faSymLink > 0 then ShowMessage('File is a symbolic link') else ShowMessage('File is not a symbolic link'); end; Show full unit code: File is not read only File is not hidden File is not a system file File is not a Volume ID File is not a directory File is archived File is not a symbolic link.
Active9 months ago

Delphi 2010 has a nice set of new file access functions in IOUtils.pas (I especially like the UTC versions of the date-related functions). What I miss so far is something like

What is the Delphi 2010-way to get the size of a file? Do I have to go back and use FindFirst to access TSearchRec.FindData?

Thanks.

Warren P
41.2k34 gold badges155 silver badges284 bronze badges
jpfolleniusjpfollenius
11.2k6 gold badges74 silver badges142 bronze badges

6 Answers

Shell Script Check File Size

I'm not sure if there's a 'Delphi 2010' way, but there is a Windows way that doesn't involve FindFirst and all that jazz.

I threw together this Delphi conversion of that routine (and in the process modified it to handle > 4GB size files, should you need that).

You could actually just use GetFileSize() but this requires a file HANDLE, not just a file name, and similar to the GetCompressedFileSize() suggestion, this requires two variables to call. Both GetFileSize() and GetCompressedFileSize() overload their return value, so testing for success and ensuring a valid result is just that little bit more awkward.

GetFileSizeEx() avoids the nitty gritty of handling > 4GB file sizes and detecting valid results, but also requires a file HANDLE, rather than a name, and (as of Delphi 2009 at least, I haven't checked 2010) isn't declared for you in the VCL anywhere, you would have to provide your own import declaration.

Shannon
4,9681 gold badge36 silver badges62 bronze badges
Delphi check file size chartDelticsDeltics
19.8k2 gold badges34 silver badges63 bronze badges
Warren P
41.2k34 gold badges155 silver badges284 bronze badges
tz.tz.

You can also use DSiFileSize from DSiWin32. Works in 'all' Delphis. Internally it calls CreateFile and GetFileSize.

Warren P

Delphi Check File Size Chart

41.2k34 gold badges155 silver badges284 bronze badges
gabrgabr
24.2k8 gold badges66 silver badges134 bronze badges

I'd like to mention few Pure Delphi ways. Though i think Deltics made a most speed-effective answer for Windows platform, yet sometimes you want just rely on RTL and also make portable code that would work in Delphi for MacOS or in FreePascal/Virtual Pascal/whatever.

There is FileSize function left from Turbo Pascal days.

Delphi Check File Size Windows 10

The sample above lacks 'read-only' mode setting. You would require that to open r/o file such as one on CD-ROM media or in folder with ACLs set to r/o. Before calling ReSet there should be zero assigned to FileMode global var.

It would not work on files above 2GB size (maybe with negative to cardinal cast - up to 4GB) but is 'out of the box' one.

There is one more approach, that you may be familiar if you ever did ASM programming for MS-DOS. You Seek file pointer to 1st byte, then to last byte, and check the difference.
I can't say exactly which Delphi version introduced those, but i think it was already in some ancient version like D5 or D7, though that is just common sense and i cannot check it.
That would take you an extra THandle variable and try-finally block to always close the handle after size was obtained.

Aside from 1st approach this is int64-capable.It is also compatible with FreePascal, though with some limitations

You can also create and use TFileStream-typed object - which was the primary, officially blessed avenue for file operations since Delphi 1.0

As a side note, this avenue is of course integrated with aforementioned IOUtils unit.

Arioch 'TheArioch 'The
Richard WinstonRichard Winston

This is a short solution using FileSize that does the job:

From what I know, FileSize is available only from XE2.

sygi
3,7172 gold badges24 silver badges42 bronze badges
pavel.lazarpavel.lazar

Delphi Check File Size

Not the answer you're looking for? Browse other questions tagged delphifiledelphi-2010 or ask your own question.