Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to find the size of a file without opening the file/stream?



Permlink Replies: 3 - Last Post: Aug 5, 2017 10:44 PM Last Post By: Timur Tekil
Timur Tekil

Posts: 25
Registered: 12/25/13
How to find the size of a file without opening the file/stream?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2017 12:26 PM
How can we find the size of a file without opening the file/stream and without using Winapi?
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: How to find the size of a file without opening the file/stream?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2017 1:09 PM   in response to: Timur Tekil in response to: Timur Tekil
Timur Tekil wrote:

How can we find the size of a file without opening the file/stream
and without using Winapi?

Open the Windows Explorer (or macOS Finder or whatever...) and look...
<g>

Seriously though, see here:

https://stackoverflow.com/a/1642355/95954

--
Rudy Velthuis http://www.rvelthuis.de

"It would seem that you have no useful skill or talent
whatsoever,' he said. 'Have you thought of going into
teaching?"
-- Terry Pratchett (Mort)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to find the size of a file without opening the file/stream?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2017 3:32 PM   in response to: Timur Tekil in response to: Timur Tekil
Timur Tekil wrote:

How can we find the size of a file without opening the file/stream
and without using Winapi?

You can't. If you don't open the file, you have to use a platform API
(directly or indirectly) to query the file's metadata from the
filesystem. For instance, you can use the RTL's FindFirst() function
in SysUtils.hpp, which will internally call the Win32 FindFirstFile()
function on Windows. Or you can call the Win32 GetFileAttributesEx()
function directly. Either function will give you the file's size
without opening the file itself.

--
Remy Lebeau (TeamB)
Timur Tekil

Posts: 25
Registered: 12/25/13
Re: How to find the size of a file without opening the file/stream?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 5, 2017 10:44 PM   in response to: Timur Tekil in response to: Timur Tekil
Thanks for your answers :)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02