## FID

PURPOSE:
To OBTAIN information about an OPENED file or device.

    STATEMENT SYNTAX:
    {stno}FID(unit)fname, ftype, direntry,#recs, recsiz, disk#, channel#, #keys,
                   keysiz, recsused, #open,#extract

where:

fname | a file or device name
ftype | 0-device 1-program 2-indexed 3-sort 4-direct 5-string 7-serial 8-mkeyed 105-directory.
direntry | Directory Entry String.
recs | number of records currently allocated to the file
recsiz | the record size in bytes (max 8192)
disk# | corresponding to a SETDISK command
channel# | OS Channel number
#keys | number of keys initially allocated to the file
keysiz | the key size in bytes (max 120)
recsused | the number of records and/or keys in use.
#open | 0 - Not Used
#extract | 0 - Not Used

    EXAMPLE:
    0010 FID(9,ERR=999)F$ To retrieve FILE NAME only
    0020 FID (1)F$,T,E$ To retrieve first 3 fields.
    0030 FID (2)*,*,*,*,*,D To obtain Disk Number only.

NOTES:
The FID command is invalid for SOCKET's (returns an error 17)
Devices only return their name.
Directories only return their path name in the fname field.
If some variables are not required, the "*" (skip field) option is available (just like any other I/O command). Parameters that are not applicable will simply yield ZERO OR NULL VALUES as warranted.
The 1st 32 bytes of directory entry are the result of an fstat command, the next 16 bytes are $00$,next 2 bytes) are an SM32 internal type number and the characters starting at byte 51 are the full path name. If a FID(1)*,*,B$ were executed then B$ will contain :

Conversion | fstat name | Description
--- | --- | ---
DEC(SWAP(B$(1,2),$01$)) | st_dev | device (always = 0)
DEC(SWAP(B$(3,2),$01$)) | st_ino | inode (=0 under windows)
SWAP(B$(5,2),$01$) | st_mode | protection see fstat for bit layout
DEC(SWAP(B$(7,2),$01$)) | st_nlink | number of hard links (=0 under windows)
DEC(SWAP(B$(9,2),$01$)) | st_uid | user ID of owner (=0 under windows)
DEC(SWAP(B$(11,2),$01$)) | st_gid | group ID of owner (=0 under windows)
DEC(SWAP(B$(13,2),$01$)) | st_rdev | device type (always =0)
B$(15,2) |  | $0000$
DEC(SWAP(B$(17,4),$03$)) | st_size | total size, in bytes
DEC(SWAP(B$(21,4),$03$)) | st_atime | time of last access
DEC(SWAP(B$(25,4),$03$)) | st_mtime | time of last modification
DEC(SWAP(B$(29,4),$03$)) | st_ctime | file creation time
B$(33,16) |  | All $00$'s
DEC(SWAP(B$(49,2),$01$)) |  | 1000 - indexed 1001 - sort 1002 - direct 1003 - serial 1004 - pipe 1005 - mkeyed1 1006 - smkeyed 1007 - program 1008 - pgmlib 1009 - mkeyed2 1010 - string 1011 - pgmlib_program 1012 - directory 1013 - pgmlib2 1014 - link
B$(51) |  | Path Name

st_atime,st_mtime and st_ctime are in UTC where 0 = Dec 31,1969 at midnight. The example below show how to extract these times using the Date Offset function.

    10 BEGIN
    20 OPEN (1)"dtest"
    30 FID (1)*,*,B$
    40 LET D$=DTO("19700101000000",DEC(SWAP(B$(29,4),$03$)))
    50 LET D$=D$(1,4)+"-"+D$(5,2)+"-"+D$(7,2)+" "+D$(9,2)+":"+D$(11,2)+":"+D$(13,2)
    60 PRINT B$(51)," was Created: ",D$
    70 LET D$=DTO("19700101000000",DEC(SWAP(B$(25,4),$03$)))
    80 LET D$=D$(1,4)+"-"+D$(5,2)+"-"+D$(7,2)+" "+D$(9,2)+":"+D$(11,2)+":"+D$(13,2)
    90 PRINT B$(51)," was Modified: ",D$
    100 LET D$=DTO("19700101000000",DEC(SWAP(B$(21,4),$03$)))
    110 LET D$=D$(1,4)+"-"+D$(5,2)+"-"+D$(7,2)+" "+D$(9,2)+":"+D$(11,2)+":"+D$(13,2)
    120 PRINT B$(51)," was Accesed: ",D$

SEE:
FID function