Science, Tech, Math › Computer Science Get the Size of a File in Bytes Using Delphi Share Flipboard Email Print Hero Images/Getty Images Computer Science Delphi Programming Delphi Tutorials Advanced PHP Programming Perl Python Java Programming Javascript Programming C & C++ Programming Ruby Programming Visual Basic View More By Zarko Gajic Zarko Gajic Twitter Computer Science Expert MSCS, Computer Science, University of Osijek Zarko Gajic is experienced in SQL and has working knowledge of DB systems such as MS SQL Server, Firebird, Interbase, and Oracle. He is also proficient in XML, DHTML, and JavaScript. Learn about our Editorial Process Updated on March 05, 2019 The FileSize function returns the size of a file, in bytes -- a useful result for certain file-handing applications within a Delphi program. Get File Size The FileSize function returns the size of a file in bytes; the function returns -1 if the file was not found. // returns file size in bytes or -1 if not found.function FileSize(fileName : wideString) : Int64;varsr : TSearchRec;beginif FindFirst(fileName, faAnyFile, sr ) = 0 thenresult := Int64(sr.FindData.nFileSizeHigh) shl Int64(32) + Int64(sr.FindData.nFileSizeLow)elseresult := -1;FindClose(sr);end; When you have the size of a file in bytes, you may wish to format the size for display (Kb, Mb, Gb) to assist your end users in comprehending the data without having to convert units. Cite this Article Format mla apa chicago Your Citation Gajic, Zarko. "Get the Size of a File in Bytes Using Delphi." ThoughtCo, Feb. 16, 2021, thoughtco.com/file-size-in-bytes-using-delphi-1057888. Gajic, Zarko. (2021, February 16). Get the Size of a File in Bytes Using Delphi. Retrieved from https://www.thoughtco.com/file-size-in-bytes-using-delphi-1057888 Gajic, Zarko. "Get the Size of a File in Bytes Using Delphi." ThoughtCo. https://www.thoughtco.com/file-size-in-bytes-using-delphi-1057888 (accessed June 4, 2023). copy citation