-
January 9th, 2010, 05:37 PM
#1
Get size of a file
Hey.
I need a way to return size of a file without opening it since it is already open from another program (actually it gets downloaded so it isn't even completed yet).
Is there a way to do this!?
Thanks.
-
January 9th, 2010, 10:05 PM
#2
Re: Get size of a file
Well, if it's not local, then only the server can tell you how big it is. Where is the file coming from, is it coming from a server in which you know the actions? I'm sure most file servers have protocol for that.
-
January 10th, 2010, 08:27 AM
#3
Re: Get size of a file
Originally Posted by ninja9578
Well, if it's not local, then only the server can tell you how big it is. Where is the file coming from, is it coming from a server in which you know the actions? I'm sure most file servers have protocol for that.
Well, I already know the full size of the file. I'm using an ftp library for downloading, but I want to know haw much that have gotten downloaded to create a progress bar.
@Peter_APIIT
What do you mean by OS specific function? Can you give me an example?
-
January 10th, 2010, 09:06 AM
#4
Re: Get size of a file
There is no standard C++ way, so you have to use the API that's provided by the operating system you want the program to run on.
Check fstat for UNIX-like OSs, GetFileSize(Ex) for MS Windows.
Note however that this might not work. If the file is open and written to, the operating system may report the filesize as 0. You should better check the ftp library you are using if it has a way to tell how many bytes have been transferred so far. I'm sure you will find something there.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Please read Information on posting before posting, especially the info on using [code] tags.
-
January 10th, 2010, 04:34 AM
#5
Re: Get size of a file
Use OS specific function.
Thanks for your help.
-
January 10th, 2010, 12:12 PM
#6
Re: Get size of a file
Oh, well what are you using to download it? If you're using libcurl I can help you, if not, then sorry.
libCURL has a callback which you have to write, which is used to write the data. You can use that to found how many bytes have been written so far, and if you already know how big it is, creating a progess bar and updating it is easy.
-
January 10th, 2010, 03:44 PM
#7
Re: Get size of a file
Hey, I forgot to say that I managed to figure it out.
I just used the stat library.
Here's the code:
Code:
const char* filename=fname;
struct stat st_buf;
stat(filename, &st_buf);
return st_buf.st_size;
Thanks to all anyway!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|