473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Getting a file size.

Hi ,
I wrote the following code in c++ (native) to get file size:

int o_get_file_length(const char * filename)
{
ifstream f (filename, ios::binary );
f.seekg (0, ios::end );
int length = f.tellg ();
f.close();
return length;

}

Is this ok, or is there a better way to get the file size?

Regards,

-Ab.
Mar 1 '06 #1
3 1033
> Hi ,
I wrote the following code in c++ (native) to get file size:

int o_get_file_length(const char * filename)
{
ifstream f (filename, ios::binary );
f.seekg (0, ios::end );
int length = f.tellg ();
f.close();
return length;

}


You could use the stat or _fstat functions.

--

Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"
Mar 1 '06 #2
Win32 API (although I know I should be talking about .NET here) has a
GetFileSize API. The one advantage of this is that it is capable of
reporting file sizes larger than 4Gb, because it uses two DWORDs for the
result. If you're not dealing with huge files then this is not an issue of
course, and I'd recommend stat as previously advised.

Kevin
"Bruno van Dooren" <br**********************@hotmail.com> wrote in message
news:E3**********************************@microsof t.com...
Hi ,
I wrote the following code in c++ (native) to get file size:

int o_get_file_length(const char * filename)
{
ifstream f (filename, ios::binary );
f.seekg (0, ios::end );
int length = f.tellg ();
f.close();
return length;

}


You could use the stat or _fstat functions.

--

Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"

Mar 2 '06 #3
Thanks for the reply to all.
Win32 API (although I know I should be talking about .NET here) has a I'm doing it in native pure c++, not using .net anywhere.
GetFileSize API. The one advantage of this is that it is capable of
Thanks for the winapi too.

Abubakar.

"Kevin Frey" <ke**********@hotmail.com> wrote in message
news:em**************@TK2MSFTNGP11.phx.gbl... Win32 API (although I know I should be talking about .NET here) has a
GetFileSize API. The one advantage of this is that it is capable of
reporting file sizes larger than 4Gb, because it uses two DWORDs for the
result. If you're not dealing with huge files then this is not an issue of
course, and I'd recommend stat as previously advised.

Kevin
"Bruno van Dooren" <br**********************@hotmail.com> wrote in message
news:E3**********************************@microsof t.com...
Hi ,
I wrote the following code in c++ (native) to get file size:

int o_get_file_length(const char * filename)
{
ifstream f (filename, ios::binary );
f.seekg (0, ios::end );
int length = f.tellg ();
f.close();
return length;

}


You could use the stat or _fstat functions.

--

Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"


Mar 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: middletree | last post by:
How do I request the actual page name that I'm on? This is going to go into an include file, and depending on which page I'm on, I'd like to do different things. I'm looking for "pagename.asp"
0
by: PlanarIndia | last post by:
hi, I am facing an issue with getting the file size of a network shared file. I tried using FileInfo.length and it is returning me size that is rounded off to the nearest 1024 bytes. E.g. for...
17
by: Arnold | last post by:
Is using fseek and ftell a reliable method of getting the file size on a binary file? I thought I remember reading somewhere it wasn't... If not what would be the "right" and portable method to...
11
by: KarimL | last post by:
Thanks for your advices... but i need to get the Image height because i dynamically resize the height of my webcontrol based on the image height. More i just have the url (relative parth) to the...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
12
by: leonard.guillaume | last post by:
Hi guys, I use dynamic char arrays and I'm trying to get rid of the garbage in it. Let me show you the code and then I'll explain more in details. ...
4
by: AshishMishra16 | last post by:
HI friends, I am using the Flex to upload files to server. I m getting all the details about the file, but I m not able to upload it to Server. Here is the code i m using for both flex & for...
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
9
vikas251074
by: vikas251074 | last post by:
I am not getting date value in spite of my good effort. This code was working in my last office where I work. Now I am trying to work at my home pc. but not getting date value. Any can help me why...
7
vikas251074
by: vikas251074 | last post by:
I am getting error above in following code since few days giving tension day and night. How can I solve this? I am facing since Oct.25. in line no. 362 After doing a lot of homework, I am...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.