how to get the size of large files ?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

how to get the size of large files ?

vatko
Hi,

I had a code in matlab that needed to know the exact size of some data file at a certain point. I used the function s = dir(filename) and read the file size in s.bytes. But this does not work in octave with very large files. I have a file that is ~3.4Go and dir tells me that the file does not exist. I also tried stat(), but it gives me an empty array. But both function work with small files of a few Mo.
Is there any other way I can get the size of a file ?

thanks
Reply | Threaded
Open this post in threaded view
|

Re: how to get the size of large files ?

Leo Butler
vatko <[hidden email]> writes:

> Hi,
>
> I had a code in matlab that needed to know the exact size of some data file
> at a certain point. I used the function s = dir(filename) and read the file
> size in s.bytes. But this does not work in octave with very large files. I
> have a file that is ~3.4Go and dir tells me that the file does not exist. I
> also tried stat(), but it gives me an empty array. But both function work
> with small files of a few Mo.
> Is there any other way I can get the size of a file ?
>
> thanks

You can use the system command, e.g.

function s = fsize(file)
 [x,s]=system(sprintf("ls -s --block-size=1 %s",file));
 s=strtok(s," ");
endfunction

This returns a string containing the file size. You can use `eval' on
that string to get a float.

Note that what you are seeing is a bug in the way that octave is
populating the structure in a call to stat. Leo

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: how to get the size of large files ?

vatko
Nice ! I am going to use that. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: how to get the size of large files ?

Leo Butler
vatko <[hidden email]> writes:

> Nice ! I am going to use that. Thank you.
>
Glad to help. If you do use that code, be sure to add some
error-handling, because it does not check to see if the file exists, if
there are multiple file sizes returned, etc.


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave