Find size of a file

  • Follow


Hi,

Can anyone please tell me is there any chance/way to find out the size
of a file/no.of rows in a file....without actually opening it and
running a loop till the end of file...?

Thanking you.
Praveen.
0
Reply ezeepraveen4u (27) 2/1/2010 11:42:14 AM

On 1 feb, 12:42, Fortran_follower <ezeepravee...@gmail.com> wrote:
> Hi,
>
> Can anyone please tell me is there any chance/way to find out the size
> of a file/no.of rows in a file....without actually opening it and
> running a loop till the end of file...?
>
> Thanking you.
> Praveen.

The size of a file is relatively easy: run a system command like "ls -
l" under
Linux or "dir" under Windows and analyse the output. Fortran-only
solutions
are compiler-dependent, though.

The second part of your question has the answer: that is impossible,
at least
in general. If your file is a direct-access file or a file with a
known structure
in general, then you can compute the number of rows/records from the
size.
Otherwise it is impossible, because modern file systems have no
concept of
what constitutes a row or record.

Regards,

Arjen
0
Reply Arjen 2/1/2010 11:52:05 AM


On 2010-02-01 07:52:05 -0400, Arjen Markus <arjen.markus895@gmail.com> said:

> On 1 feb, 12:42, Fortran_follower <ezeepravee...@gmail.com> wrote:
>> Hi,
>> 
>> Can anyone please tell me is there any chance/way to find out the size
>> of a file/no.of rows in a file....without actually opening it and
>> running a loop till the end of file...?
>> 
>> Thanking you.
>> Praveen.
> 
> The size of a file is relatively easy: run a system command like "ls -
> l" under
> Linux or "dir" under Windows and analyse the output. Fortran-only
> solutions
> are compiler-dependent, though.
> 
> The second part of your question has the answer: that is impossible,
> at least
> in general. If your file is a direct-access file or a file with a
> known structure
> in general, then you can compute the number of rows/records from the
> size.
> Otherwise it is impossible, because


> modern file systems

Surely you mean "simple file systems" as unfortunately many current
popular computers (really operating systems) have file system with very
old historic roots. There is nothing modern about them except their
marketing. There are also several updated disk data structures but
that is not to be confused with their being modern as file systems.

> have no
> concept of
> what constitutes a row or record.
> 
> Regards,
> 
> Arjen


0
Reply Gordon 2/1/2010 1:40:24 PM

On 1 feb, 14:40, Gordon Sande <g.sa...@worldnet.att.net> wrote:
>
> Surely you mean "simple file systems" as unfortunately many current
> popular computers (really operating systems) have file system with very
> old historic roots. There is nothing modern about them except their
> marketing. There are also several updated disk data structures but
> that is not to be confused with their being modern as file systems.
>

Ah, I have been trappen by for the marketing pitch. Yes, I mean:
the file systems you find on PCs and laptops running Linux or Windows
and, probably, their Apple/OSX counterparts.

(I have worked with an IBM minicomputer that did keep the file
structure
as part of its directory information, but that is a long time ago ...)

Regards,

Arjen
0
Reply Arjen 2/1/2010 2:47:24 PM

Fortran_follower wrote:
> Hi,
>=20
> Can anyone please tell me is there any chance/way to find out the size
> of a file/no.of rows in a file....without actually opening it and
> running a loop till the end of file...?
>=20
> Thanking you.
> Praveen.

There have been operating systems in which the default format for a file =
as actually stored was to include in a header information such as the =
file size (of two types, actual used and reserved size) and number of =
records. System-specific Fortran routines were available to access =
these. So the minute chance exists that you may be using a system such =
as this, one of which was a Honeywell of the 80's.

David Jones
0
Reply David 2/1/2010 2:58:01 PM

Fortran_follower wrote:
> 
> Hi,
> 
> Can anyone please tell me is there any chance/way to find out the size
> of a file/no.of rows in a file....without actually opening it and
> running a loop till the end of file...?

I have frequently found it most useful to run a dummy loop to count the
number of lines in a text file, like you said, before allocating arrays
and reading the actual data.  This is a simple, standard fortran
solution that does not use any processor dependent methods, so I
encourage this method even though it seems inefficient.

On modern computers, this method is fast and effective for all but the
most enormous of data files.  It seems that in modern operating systems,
the second pass reads from an in-memory cache rather than from disk,
thus making the time penalty almost imperceptible.

--Dave
0
Reply Dave 2/1/2010 5:41:16 PM

5 Replies
340 Views

(page loaded in 0.098 seconds)

Similiar Articles:













7/29/2012 11:59:02 AM


Reply: