Delphi Check File Size

All about Borland Delphi. Programming tips, downloads. Find the size of a file? For some reason both methods of finding file size return. May 08, 2012 You should just be able to check if TIdFtp. Vsam Files In Informatica Powercenter. Size(remoteFilename) has the same size as the stream that you sent to the server using the Put command.
16 Tenses In English Grammar Pdf on this page. This should be easy, but I cannot seem to get it right as I seem to be confusing myself and converting to and from strings, integers and floats and whatnot. Basically, I am populating a TListView with FileNames in one column, and in another column returning the File Size to the corresponding FileName. I am using a rather neat function found from, which looks like this: function FileSizeStr ( filename: string ): string; const // K = Int64(1000); // Comment out this line OR K = Int64(1024); // Comment out this line M = K * K; G = K * M; T = K * G; var size: Int64; handle: integer; begin handle:= FileOpen(filename, fmOpenRead); if handle = -1 then result:= 'Unable to open file ' + filename else try size:= FileSeek ( handle, Int64(0), 2 ); if size.
I'm not sure if there's a 'Delphi 2010' way, but there is a. I threw together this Delphi conversion of that routine (and in the process modified it to handle >4GB size files, should you need that). Function FileSize(const aFilename: String): Int64; var info: TWin32FileAttributeData; begin result:= -1; if NOT GetFileAttributesEx(PWideChar(aFileName), GetFileExInfoStandard, @info) then EXIT; result:= Int64(info.nFileSizeLow) or Int64(info.nFileSizeHigh shl 32); end; 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. GetFileSize Ex() 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. For a compressed file (zip, rar, 7z etc) it will report the size of the archive in bytes, not the size of the decompressed contents.
But for a ZIP file, the size of the file IS the size of the archive. For a file on a compressed volume it will report the size of the decompressed file, which is what you want because you are asking for the size of the storage object (the file) not the physical storage medium (the OS enforced compression). 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. Passion Our Love Is Loud Rarest. • • • 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.