Sheerpower Logo
F.4  FILEINFO$() File Information Function

FILEINFO$ Function Documentation

FILEINFO$ Function

The FILEINFO$ function parses a file specification and returns either a full file specification or specific file specification fields.

Syntax

FILEINFO$(str_expr1 [, str_expr2 [, str_expr3]])

Parameters

  • str_expr1 - The file specification to be parsed. If no file specification is given, the device and directory you are currently running from are returned.
  • str_expr2 - A list of field names, separated by commas, which are to be returned. The field names are:
    • CONTENTS - File contents
    • DEVICE - Drive name
    • DIRECTORY - Directory name
    • NAME - File name
    • TYPE - Type or extension name
    • LOCATION - Device and directory names
    • BACKUP_DATE - Last file backup date
    • CREATION_DATE - Date file was created
    • EXPIRATION_DATE - File expiration date
    • REVISION_DATE - Date file was last modified
    • REVISION - The number of times a given file has been revised (given that the underlying OS supports this)
    • SIZE - The size of the file in bytes
    • ALL or "" - Full file specification
  • str_expr3 - The default file specification. This parameter is optional.

Examples

Basic Usage of FILEINFO$

Note: In Sheerpower, when specifying file paths, the '@' symbol at the beginning of a path refers to the directory of the currently running program. This makes it easy to reference files relative to your program's location, enhancing portability and simplifying path management.

    print fileinfo$('x.y', 'ALL') 
    print fileinfo$('', 'ALL') 
    end
    

Output:


    c:\Sheerpower\x.y 
    c:\Sheerpower 
    

Using Default File Specification


    x$ = 'Sheerpower:samples\client' 
    print fileinfo$(x$, 'ALL', '.ars') 
    end
    

Output:


    c:\Sheerpower\samples\client.ars 
    

Example 6-175: Various Field Names


    print fileinfo$('Sheerpower:\samples\client', 'all', '.ars') 
    print fileinfo$('Sheerpower:\samples\client', 'location') 
    print fileinfo$('Sheerpower:\samples\client', 'location, name') 
    print fileinfo$('Sheerpower:\samples\client.ars') 
    end
    

Output:


    c:\Sheerpower\samples\client.ars 
    c:\Sheerpower\samples\ 
    c:\Sheerpower\samples\client 
    c:\Sheerpower\samples\client.ars 
    

FILEINFO$ Contents Option

The CONTENTS option of FILEINFO$ returns the entire contents of the file 'some_file.xxx' into all_of_file$. If the file cannot be found, then it returns a null string. A zero-length file will also return a null string.

FORMAT


    all_of_file$ = fileinfo$('some_file.xxx', 'contents') 
    

Using FILEINFO$ to Retrieve File Contents


    all_of_file$ = fileinfo$('Sheerpower:Sheerpower.ini', 'contents') 
    print all_of_file$ 
    end
    

Output:


    [license] 
    LicenseKey=F0CE-2E43-7583-3130-3030-3030-3131-0003-873F-000A 
    Username=non-commercial 
    EmailAddress=non-commercial 
    

Copy a File with FILEINFO$ CONTENTS


    sourcefile$ = 'source.xxx' 
    destfile$   = 'destination.xxx' 
    contents$   = fileinfo$(sourcefile$, 'contents') 
    open file dest_ch: name destfile$, access output, unformatted
    print #dest_ch: contents$ 
    close #x 
    end
    
Hide Description

    

       


      

Enter or modify the code below, and then click on RUN

Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use.
Wide screen