其实用stat函数即可实现:
STAT
Portability Function: Returns detailed information about a file.
Module: USE DFPORT
Syntax
result = STAT (name, statb)
name
(Input) Character*(*). Name of the file to examine.
statb
(Output) INTEGER(4). One-dimensional array with a size of 12.
Results:
The result is of type INTEGER(4). The result is zero if the inquiry was successful; otherwise, the error code ENOENT (the specified file could not be found). For a list of other error codes, see IERRNO.
The elements of statb contain the following values:
Element Description Notes
statb(1) Device file resides on Always 0
statb(2) File Inode number Always 0
statb(3) Access mode of the file (See following table)
statb(4) Number of hard links Always 1
statb(5) User ID of owner Always 1
statb(6) Group ID of owner Always 1
statb(7) Raw device file resides on Always 0
statb(8) Size of the file in bytes
statb(9) Time when the file was last accessed (Only available on non-FAT file systems; undefined on FAT systems)
statb(10) Time when the file was last modified
statb(11) Time of last file status change Same as stat(10)
statb(12) Blocksize Always 1
Times are in the same format returned by the TIME function (number of seconds since 00:00:00 Greenwich mean time, January 1, 1970).
- program file_size
- implicit none
- INTEGER*4 ierr, stat, statb(13)
- ierr = stat ( 'rsl.out.0000', statb )
- if ( ierr .ne. 0 ) stop 'stat: error'
- write(*,*)'The size of the file in bytes = ',statb(8)
- end program file_size
|