IRISLIB database
File Class Reference
Inheritance diagram for File:
Collaboration diagram for File:

Public Member Functions

_.Library.Status OnClose ()
 This callback method is invoked by the <METHOD>Close</METHOD> method to. More...
 
_.Library.Status Clear ()
 Clear the contents of this Stream from permanent storage. More...
 
 Close ()
 Close the current file.
 
_.Library.Status CopyFromAndSave (_.Library.AbstractStream source)
 Method not implemented as it does not make sense in context of File interface.
 
_.Library.Status Open (_.Library.String mode, _.Library.Integer timeout)
 Open the current file with mode mode. More...
 
_.Library.RawString Read (_.Library.Integer len, _.Library.Status sc)
 Read up to len characters from this File.
 
_.Library.Status Rewind ()
 Moves the current location to the beginning of the stream.
 
_.Library.Boolean SetFileDateModified (_.Library.String filename, _.Library.TimeStamp ntime, _.Library.Boolean utc, _.Library.Integer return)
 Set the date last modified of file filename to be ntime in $H format. More...
 
_.Library.Status Write (_.Library.RawString data)
 Write data to this <CLASS>File</CLASS> object.
 
_.Library.Status WriteLine (_.Library.RawString data)
 Write data with a carriage return to this <CLASS>File</CLASS> object.
 
- Public Member Functions inherited from AbstractStream
_.Library.Status CopyFrom (_.Stream.Object source)
 Copies the contents of source into this Stream. More...
 
_.Library.Boolean DeleteAttribute (_.Library.String name)
 Removes this attribute variable from the collection. More...
 
_.Library.Status Flush ()
 Flush any output in the stream not already saved.
 
_.Library.String GetAttribute (_.Library.String name, _.Library.String default)
 Retrieves the named attribute value.
 
_.Library.String GetStreamId ()
 Returns an full id value (including class name) with which the Stream implementation has stored. More...
 
_.Library.Boolean IsDefinedAttribute (_.Library.String name)
 Returns true if the named attribute variable exists in the collection, false otherwise.
 
_.Library.Boolean IsNull ()
 Returns true if this is a "NULL" stream; that is, a stream which has never. More...
 
_.Library.Status MoveToEnd ()
 Move to the end of the stream so the next <METHDO>Write</METHOD> will be appended to the end. More...
 
_.Library.String NextAttribute (_.Library.String name)
 Retrieves the next attribute variable name in the sequence, skip any '' names.
 
_.Library.AbstractStream ReadLineIntoStream ()
 This reads from the stream until it find the <property>LineTerminator</property> and returns. More...
 
_.Library.Status SaveStream ()
 Deprecated method, use <method>Save</method> instead. More...
 
 SetAttribute (_.Library.String name, _.Library.String value)
 Inserts an attribute variable by name into the collection.
 
- Public Member Functions inherited from Object
_.Library.Status AcquireLock (locktype)
 Acquires a lock for the current instance. More...
 
_.Library.Status OnAfterSave (_.Library.Boolean insert)
 This callback method is invoked by the <METHOD>Save</METHOD> method to. More...
 
_.Library.Status OnBeforeSave (_.Library.Boolean insert)
 This callback method is invoked by the <METHOD>Save</METHOD> method to. More...
 
_.Library.Status OnOpen ()
 This callback method is invoked by the <METHOD>Open</METHOD> method to. More...
 
_.Library.Status OnReload ()
 This callback method is invoked by the <METHOD>Reload</METHOD> method to. More...
 
_.Library.Status OnRollBack ()
 This callback method is invoked by the <METHOD>Save</METHOD> method to. More...
 
_.Library.Status CopyFrom (_.Stream.Object source)
 Copies the contents of source into this Stream. More...
 
_.Library.Status CopyFromAndSave (_.Stream.Object source)
 Copy the stream from source into the current stream ignoring anything already in the current stream. More...
 
_.Library.Integer FindAt (_.Library.Integer position, _.Library.RawString target, _.Library.RawString tmpstr, _.Library.Boolean caseinsensitive)
 Find the first occurrence of target in the stream, starting the search at position. More...
 
_.Library.Status InputFromDevice (_.Library.Integer len, _.Library.Integer timeout)
 Input len characters from the current device into the stream. More...
 
_.Library.Boolean MoveTo (_.Library.Integer position)
 Move to this position in the stream. More...
 
_.Library.Status OutputToDevice (_.Library.Integer len)
 Write out len characters of the stream to the current device starting from the current position. More...
 
_.Library.Status OutputToDeviceAt (_.Library.Integer position, _.Library.Integer length)
 Output the stream to the current device starting at position of length. More...
 
_.Library.RawString Read (_.Library.Integer len, _.Library.Status sc)
 Reads up to len characters from the current position. More...
 
_.Library.RawString ReadLine (_.Library.Integer len, _.Library.Status sc, _.Library.Boolean eol)
 Read a line from the stream. More...
 
_.Library.String ReadSQL (_.Library.Integer start, _.Library.Integer end)
 SQL specific method for reading stream data.
 
_.Library.Status SerializeToSyncSet (_.SYNC.SyncSet ss, _.Library.Integer iPtr, _.Library.String property)
 SerializeToSyncSet copies the stream value from the current object to the sync set global. More...
 
_.Library.Status SyncStreamIn (_.SYNC.SyncSet ss, _.Library.Integer iPtr, _.Library.String property)
 SyncStreamIn copies the stream value from the sync set global into the current object.
 
_.Library.Status Write (_.Library.RawString data)
 Appends the string data to the stream and advances the. More...
 
_.Library.Status WriteLine (_.Library.RawString data)
 Appends the string data along with a line terminator to the stream and advances the. More...
 
- Public Member Functions inherited from RegisteredObject
_.Library.Status OnAddToSaveSet (_.Library.Integer depth, _.Library.Integer insert, _.Library.Integer callcount)
 This callback method is invoked when the current object is added to the SaveSet,. More...
 
_.Library.Status OnConstructClone (_.Library.RegisteredObject object, _.Library.Boolean deep, _.Library.String cloned)
 This callback method is invoked by the <METHOD>ConstructClone</METHOD> method to. More...
 
_.Library.Status OnNew ()
 This callback method is invoked by the <METHOD>New</METHOD> method to. More...
 
_.Library.Status OnValidateObject ()
 This callback method is invoked by the <METHOD>ValidateObject</METHOD> method to. More...
 

Static Public Member Functions

_.Library.String Attributes (_.Library.String filename)
 Return the attributes of the file. More...
 
_.Library.String CanonicalFilename (_.Library.String filename)
 Returns the canonical form of the filename. More...
 
_.Library.Boolean Compare (_.Library.String file1, _.Library.String file2)
 Compare two files and return 1 if they are identical and 0 otherwise.
 
_.Library.Boolean ComplexDelete (_.Library.String filename, _.Library.Integer return)
 Handle delete of cases where filename contains a wildcard. More...
 
_.Library.String ComputeFullDBDir (_.Library.String filename)
 Return the canonical form of the directory name filename. More...
 
_.Library.String Construct (_.Library.String dirs)
 Pass in an array of paths you want to turn into a filename for the server platform, for example: More...
 
_.Library.Boolean CopyDir (_.Library.String pSource, _.Library.String pTarget, _.Library.Boolean pOverlay, pCreated, _.Library.Boolean pDeleteBeforeCopy)
 Copy a host directory from pSource to pTarget. More...
 
_.Library.Boolean CopyFile (_.Library.String from, _.Library.String to, _.Library.Boolean pDeleteBeforeCopy, _.Library.Integer return)
 Copy a host file from to host file to. More...
 
_.Library.Boolean CreateDirectory (_.Library.String name, _.Library.Integer return)
 Creates a directory with name name. More...
 
_.Library.Boolean CreateDirectoryChain (_.Library.String name, _.Library.Integer return)
 Create this directory and all the parent directories if they do not exist. More...
 
_.Library.Boolean CreateNewDir (_.Library.String directory, _.Library.String name, _.Library.Integer return)
 Given a directory name and the name of a new directory create this directory inside. More...
 
 Deconstruct (_.Library.String filename, _.Library.String dirs)
 Pass in a full valid filename for the server platform and it will decompose it into the dirs array. More...
 
_.Library.Boolean Delete (_.Library.String filename, _.Library.Integer return)
 Deletes the file filename. More...
 
_.Library.Boolean DirectoryExists (_.Library.String filename)
 Tests if filename is a directory. More...
 
_.Library.Boolean Exists (_.Library.String filename, _.Library.Integer return)
 Returns true (1) if filename exists. More...
 
_.Library.String GetDirectory (_.Library.String name, _.Library.Boolean keepterm)
 Given a full directory and filename this will return just the directory portion of this name. More...
 
_.Library.Integer GetDirectoryLength (_.Library.String name)
 Return the number of pieces in this directory name.
 
_.Library.String GetDirectoryPiece (_.Library.String name, _.Library.Integer piece, _.Library.String fullpath, _.Library.Boolean IsDrive)
 Return the piece of a directory name.
 
_.Library.Status GetDirectorySpace (_.Library.String Name, _.Library.String FreeSpace, _.Library.String TotalSpace, _.Library.Integer Flag)
 Return the amount of total space and free space in either Bytes,MB,GB on a drive or directory. More...
 
_.Library.String GetFileDateCreated (_.Library.String filename, _.Library.Boolean utc)
 Return the date created of file filename in $H format,. More...
 
_.Library.String GetFileDateModified (_.Library.String filename, _.Library.Boolean utc)
 Return the date last modified of file filename in $H format. More...
 
_.Library.String GetFileSHA256Hash (_.Library.String filename, sc)
 Return the SHA 256 hash of file filename.
 
_.Library.Integer GetFileSize (_.Library.String filename)
 Return the size of file filename in bytes.
 
_.Library.String GetFilename (_.Library.String name)
 Given a full directory and filename this will return just the filename portion of this name. More...
 
_.Library.Status GetOwnerGroup (_.Library.String File, _.Library.String OwnerGroup)
 Return the Owner and Group of a file or directory in the format Owner:Group. More...
 
_.Library.String ManagerDirectory ()
 Returns the path of the manager directory.
 
_.Library.String NormalizeDirectory (_.Library.String directory, _.Library.String absolutedirectory, _.Library.Boolean addnull)
 Returns a normalized absolute directory from the directory that is passed in including any trailing directory delimiter. More...
 
_.Library.String NormalizeFilename (_.Library.String filename, _.Library.String directory)
 Returns the normalized form of the filename. More...
 
_.Library.String NormalizeFilenameWithSpaces (_.Library.String pathname)
 Normalize filenames containing spaces for the host platform. More...
 
_.Library.String ParentDirectoryName (_.Library.String directory)
 Given a directory name, return the name of its parent directory. More...
 
_.Library.Boolean ReadOnly (_.Library.String filename)
 Return true if the file is read only and false if it is writable.
 
_.Library.Boolean RemoveDirectory (_.Library.String name, _.Library.Integer return)
 Removes directory name. More...
 
_.Library.Boolean RemoveDirectoryTree (_.Library.String pTarget)
 Recursively remove directory pTarget. More...
 
_.Library.Boolean Rename (_.Library.String oldname, _.Library.String newname, _.Library.Integer return)
 Rename file oldname to newname. More...
 
_.Library.String SHA1Hash (_.Library.String file, _.Library.Integer type)
 Return binary form of SHA1 hash on the file if type is 0 (the default). More...
 
_.Library.Boolean SetAttributes (_.Library.String filename, _.Library.String attributes, _.Library.Integer return)
 Set the OS specific attributes of the file. More...
 
_.Library.Status SetOwnerGroup (filename, OwnerGroup)
 Set the Owner and Group of a file or directory. More...
 
_.Library.Boolean SetReadOnly (_.Library.String filename, _.Library.Boolean leaveexisting, _.Library.Integer return)
 Make this file/directory read only (if we can). More...
 
_.Library.Integer SetUMask (_.Library.Integer NewMask)
 Set umask to the given value and return the previous umask value. More...
 
_.Library.Boolean SetWriteable (_.Library.String filename, _.Library.Boolean writeonly, _.Library.Integer return)
 Make this file/directory writable (if we can). More...
 
_.Library.String SubDirectoryName (_.Library.String directory, _.Library.String name, _.Library.Boolean normalized)
 Given a directory name and the name of a sub directory create the name for the. More...
 
_.Library.String TempFilename (_.Library.String ext, _.Library.String dir, _.Library.Integer return)
 Return a temporary filename in the OS provided temp directory or the directory. More...
 
_.Library.Boolean Truncate (_.Library.String filename, _.Library.Integer return)
 Truncate an existing file or create a new empty file. More...
 
_.Library.Boolean Writeable (_.Library.String filename)
 Return true if the file/directory is writable and false if it is not.
 
- Static Public Member Functions inherited from AbstractStream
_.Library.Status DeleteStream (_.Library.ObjectIdentity oid, _.Library.Integer concurrency)
 Deprecated method, use <method>Delete</method> instead. More...
 
- Static Public Member Functions inherited from Object
_.Library.String GetLockReference (_.Library.String pLocation, _.Library.String pId)
 Returns the global reference used to lock the current stream object. More...
 
_.Library.Status OnDelete (_.Library.ObjectIdentity oid)
 This callback method is invoked by the <METHOD>Delete</METHOD> method to. More...
 
_.Library.String IsCharacter ()
 Return true if this is a character stream and false if it is a binary stream.
 
_.Library.Boolean StreamOIDIsNull (_.Library.ObjectIdentity soid)
 Return true if this stream oid is a null stream and false if the stream is not null.
 

Public Attributes

 CanonicalName
 Read only property that returns the canonical filename if the file is open and "" if the file is not open. More...
 
 DateCreated
 The creation date for this file (rounded to the millisecond). More...
 
 DateModified
 The last modified date for this file (rounded to the millisecond). More...
 
 IsOpen
 True (1) if this file is currently open, false (0) otherwise. More...
 
 Name
 The name of this file. More...
 
- Public Attributes inherited from AbstractStream
 Attributes
 An array of strings containing any attribute values associated with this stream. More...
 
 LineTerminator
 Type of line terminator we use for this stream, defaults to Cr/Lf. More...
 
- Public Attributes inherited from Object
 AtEnd
 The AtEnd property is set to true (1) when, during a read,. More...
 
 LastModified
 LastModified is a read-only property containing the <class>TimeStamp</class> of More...
 
 Size
 Size is a read-only property containing the current size of the stream (in bytes More...
 

Static Public Attributes

 SQLPUBLICSECURITY = None
 
- Static Public Attributes inherited from AbstractStream
 MAXLEN = None
 The maximum number of characters (or bytes) allowed in a stream.
 
 PROPERTYVALIDATION = None
 Turns off property validation.
 
- Static Public Attributes inherited from Object
 DEFAULTCONCURRENCY = None
 
- Static Public Attributes inherited from RegisteredObject
 CAPTION = None
 Optional name used by the Form Wizard for a class when generating forms. More...
 
 JAVATYPE = None
 The Java type to be used when exported.
 
 PROPERTYVALIDATION = None
 This parameter controls the default validation behavior for the object. More...
 

Detailed Description

For information on this class, see Using Library.File.

The <CLASS>File</CLASS> class represents a disk file. It contains a number of class methods that provide a number of file system services.

For example,

If ##class(File).Exists("file.txt") Write "It exists",!

You can also create an instance of a <CLASS>File</CLASS> object that represents a particular file. <CLASS>File</CLASS> makes a number of file attributes accessible as properties as well as providing a <CLASS>AbstractStream</CLASS> interface on the file.

For example,

Set file=##class(File).New("file.txt") Write file.Size Do file.Open("WSN") Do file.WriteLine("This is a line of text")

Note that this class is a fairly simple wrapper around the ObjectScript file commands. For simply reading/writing to a file it is suggested that you look at the <class>Stream.FileCharacter</class> and <class>Stream.FileBinary</class> classes. These open the file using the correct mode automatically in order to read or write to the file and so are simpler to use.

Member Function Documentation

◆ OnClose()

_.Library.Status OnClose ( )

This callback method is invoked by the <METHOD>Close</METHOD> method to.

provide notification that the current object is being closed.

The return value of this method is ignored.

Reimplemented from AbstractStream.

◆ Attributes()

_.Library.String Attributes ( _.Library.String  filename)
static

Return the attributes of the file.

The format of the returned value depends on the underlying operating system.

Microsoft Windows® returns a value as a combination of bits whose meaning is:

  • 1: 0x00001 - Read-only
  • 2: 0x00002 - Hidden
  • 4: 0x00004 - System
  • 8: 0x00008 - Unused
  • 16: 0x00010 - Directory
  • 32: 0x00020 - Archive
  • 64: 0x00040 - Device
  • 128: 0x00080 - Normal
  • 256: 0x00100 - Temporary
  • 512: 0x00200- Sparse File
  • 1024: 0x00400 - Reparse Point
  • 2048: 0x00800 - Compressed
  • 4096: 0x01000 - Offline
  • 8192: 0x02000 - Content Not Indexed
  • 16384: 0x04000 - Encrypted
  • 32768: 0x08000 - Unused
  • 65536: 0x10000 - Virtual

In UNIX®, the returned value represents the mode map:

  • 1: 0x0001 - execute permission for others
  • 2: 0x0002 - write permission for others
  • 4: 0x0004 - read permission for others
  • 7: 0x0007 - mask for others permissions
  • 8: 0x0008 - execute permission for group
  • 16: 0x0010 - write permission for group
  • 32: 0x0020 - read permission for group
  • 56: 0x0038 - mask for group permissions
  • 64: 0x0040 - execute permission for owner
  • 128: 0x0080 - write permission for owner
  • 256: 0x0100 - read permission for owner
  • 448: 0x01C0 - mask for file owner permissions
  • 512: 0x0200 - sticky bit
  • 1024: 0x0400 - set groupid
  • 2048: 0x0800 - set userid
  • 4096: 0x1000 - fifo
  • 8192: 0x2000 - character device
  • 16384: 0x4000 - directory
  • 24576: 0x6000 - block device
  • 32768: 0x8000 - regular file
  • 40960: 0xA000 - symbolic link
  • 49152: 0xC000 - socket
  • 61440: 0xF000 - mask for file type

Note: Individual Operating System vendor differences may exist. The relevant man/help pages or other associated documentation should be consulted for a definitive description of the file attributes on a given system.

◆ CanonicalFilename()

_.Library.String CanonicalFilename ( _.Library.String  filename)
static

Returns the canonical form of the filename.

If the file can not be opened then it will return ""

◆ Clear()

_.Library.Status Clear ( )

Clear the contents of this Stream from permanent storage.

This will remove the permanent stream storage and

any temporary stream and initialise the stream to its initial state that it starts in, including removing all the stream attributes.

Returns a <CLASS>Status</CLASS> value indicating success or failure.

Reimplemented from Object.

◆ ComplexDelete()

_.Library.Boolean ComplexDelete ( _.Library.String  filename,
_.Library.Integer  return 
)
static

Handle delete of cases where filename contains a wildcard.

Note: this does not delete subdirectories in the given directory; only files are removed. Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code.

◆ ComputeFullDBDir()

_.Library.String ComputeFullDBDir ( _.Library.String  filename)
static

Return the canonical form of the directory name filename.

When filename is a non-full path directory, it will prefix the filename with Manager Path instead of current directory.

◆ Construct()

_.Library.String Construct ( _.Library.String  dirs)
static

Pass in an array of paths you want to turn into a filename for the server platform, for example:

Set dirs($i(dirs))=$system.Util.DataDirectory() Set dirs($i(dirs))="httpd" Set dirs($i(dirs))="logs" Set filename=##class(File).Construct(dirs...)

If you want the name returned to be a directory terminated with a '/' or '\' then pass in a null dirs entry as the last piece. You can also call <method>Deconstruct</method> with the returned filename to turn this back into an array like dirs. If you pass in a blank array it will return the default directory.

◆ CopyDir()

_.Library.Boolean CopyDir ( _.Library.String  pSource,
_.Library.String  pTarget,
_.Library.Boolean  pOverlay,
  pCreated,
_.Library.Boolean  pDeleteBeforeCopy 
)
static

Copy a host directory from pSource to pTarget.


Parameter pOverlay Parameter pDeleteBeforeCopy may be used to specify that any file that already exists in the target directory should be deleted before being overwritten with the source file. The default is 0 or false.
This method returns true if it succeeds and false otherwise.
Note: (1) If the target directory exists and pOverlay is false (default), then the operation fails. Also, if any of the target files exist and pDeleteBeforeCopy is false (default), then the operation may fail usually due to operating system characteristics. (2) The total number of files or directories created/copied during the operation can be gotten by passing a byref value in pCreated.

◆ CopyFile()

_.Library.Boolean CopyFile ( _.Library.String  from,
_.Library.String  to,
_.Library.Boolean  pDeleteBeforeCopy,
_.Library.Integer  return 
)
static

Copy a host file from to host file to.


Parameter pDeleteBeforeCopy may be used to specify that if the target file already exists then it should be deleted before being overwritten with the source file. The default is 0 or false.
This method returns true if it succeeds and false otherwise. Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code or of an IRIS simulated operating system return code.
Also see $SYSTEM.Process.OSError().

◆ CreateDirectory()

_.Library.Boolean CreateDirectory ( _.Library.String  name,
_.Library.Integer  return 
)
static

Creates a directory with name name.

Returns true if it succeeds and false otherwise.

Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code.

◆ CreateDirectoryChain()

_.Library.Boolean CreateDirectoryChain ( _.Library.String  name,
_.Library.Integer  return 
)
static

Create this directory and all the parent directories if they do not exist.

This differs from

<method>CreateDirectory</method> as that method only creates one new directory where as this will create the entire chain of directories. Returns true if it succeeds and false otherwise. Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code.

◆ CreateNewDir()

_.Library.Boolean CreateNewDir ( _.Library.String  directory,
_.Library.String  name,
_.Library.Integer  return 
)
static

Given a directory name and the name of a new directory create this directory inside.

the given directory. Return true if it succeeds and false otherwise. Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code.

◆ Deconstruct()

Deconstruct ( _.Library.String  filename,
_.Library.String  dirs 
)
static

Pass in a full valid filename for the server platform and it will decompose it into the dirs array.

with each integer subscript being a part of the path, this array can then be passed into <method>Construct</method> to reconstruct the filename again. So on a Unix server you need to pass this a valid Unix filename and on a Windows server this should be passed a Windows filename.

◆ Delete()

_.Library.Boolean Delete ( _.Library.String  filename,
_.Library.Integer  return 
)
static

Deletes the file filename.

Returns true if it succeeds and false otherwise.

Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code.

◆ DirectoryExists()

_.Library.Boolean DirectoryExists ( _.Library.String  filename)
static

Tests if filename is a directory.

returns 1 if it is a directory, otherwise, returns 0.

◆ Exists()

_.Library.Boolean Exists ( _.Library.String  filename,
_.Library.Integer  return 
)
static

Returns true (1) if filename exists.

Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code.

◆ GetDirectory()

_.Library.String GetDirectory ( _.Library.String  name,
_.Library.Boolean  keepterm 
)
static

Given a full directory and filename this will return just the directory portion of this name.

This is useful as the parsing of filenames on Unix/Windows is different.

◆ GetDirectorySpace()

_.Library.Status GetDirectorySpace ( _.Library.String  Name,
_.Library.String  FreeSpace,
_.Library.String  TotalSpace,
_.Library.Integer  Flag 
)
static

Return the amount of total space and free space in either Bytes,MB,GB on a drive or directory.


Name = Valid Drive or directory specification
Flag = 0 - Return bytes
Flag = 1 - Return MB (Default)
Flag = 2 - Return GB

MB and GB returned are rounded to 2 decimal places.
Any error status returned is O/S level error. Note that on Windows only drives have a measurement for free space and directories can not so the FreeSpace is only returned for drives.

◆ GetFileDateCreated()

_.Library.String GetFileDateCreated ( _.Library.String  filename,
_.Library.Boolean  utc 
)
static

Return the date created of file filename in $H format,.

if the operating system supports it. Windows is the only current platform that tracks the created date. Other systems return the date of the last file "status" change. By default this is local time. If you pass utc as true it returns it in UTC time. The value is rounded to millisecond precision.

◆ GetFileDateModified()

_.Library.String GetFileDateModified ( _.Library.String  filename,
_.Library.Boolean  utc 
)
static

Return the date last modified of file filename in $H format.

By default this is local time. If you pass utc as true it returns it in UTC time. The value is rounded to millisecond precision.

◆ GetFilename()

_.Library.String GetFilename ( _.Library.String  name)
static

Given a full directory and filename this will return just the filename portion of this name.

This is useful as the parsing of filenames on Unix/Windows is different.

◆ GetOwnerGroup()

_.Library.Status GetOwnerGroup ( _.Library.String  File,
_.Library.String  OwnerGroup 
)
static

Return the Owner and Group of a file or directory in the format Owner:Group.


◆ NormalizeDirectory()

_.Library.String NormalizeDirectory ( _.Library.String  directory,
_.Library.String  absolutedirectory,
_.Library.Boolean  addnull 
)
static

Returns a normalized absolute directory from the directory that is passed in including any trailing directory delimiter.

If the directory is a relative path (rather than an absolute path) then the absolutedirectory parameter determines what we normalize the directory compoent relative to. If absolutedirectory is "" or not passed in then we normalize relative to the current default directory otherwise we will normalize relative to the passed in absolutedirectory.

addnull use is deprecated

◆ NormalizeFilename()

_.Library.String NormalizeFilename ( _.Library.String  filename,
_.Library.String  directory 
)
static

Returns the normalized form of the filename.

If you pass directory then it will normalize this filename relative to the provided directory, if no directory is supplied then it is relative to the current default directory. If the directory does not exist then this method will return the empty string. Otherwise, this method returns the normalized full path name of the specified file.

◆ NormalizeFilenameWithSpaces()

_.Library.String NormalizeFilenameWithSpaces ( _.Library.String  pathname)
static

Normalize filenames containing spaces for the host platform.



Parameter
pathname : A filename or pathname.

Description
The NormalizeFilenameWithSpaces class method handles spaces in pathnames as appropriate to the host platform.

If a pathname contains spaces NormalizeFilenameWithSpaces returns the pathname enclosed in double quotes ("path name"). If a pathname does not contain spaces, the method returns it unchanged. NormalizeFilenameWithSpaces performs no other pathname validation.

NormalizefilenameWithSpaces is commonly used with the $ZF() functions.

Note that this method does not perform the normalization actions of <method>NormalizeFilename</method>.

◆ Open()

_.Library.Status Open ( _.Library.String  mode,
_.Library.Integer  timeout 
)

Open the current file with mode mode.

<p><var>mode</var> is a string containing one or more file modes including:
<table COLS=2>
<tr><TD><B>R</B></TD><TD>Read</TD></tr>
<tr><TD><B>W</B></TD><TD>Write</TD></tr>
<tr><TD><B>S</B></TD><TD>Stream mode</TD></tr>
<tr><TD><B>N</B></TD><TD>Create a new file (overwrite existing file)</TD></tr>
</table>
Note that if the <var>mode</var> contains ':' characters this is a delimiter.
For example if the mode="RN:/SHARED" then it will open the file with the equivalent
of the COS command 'Open name:("RN":/SHARED):0'. The first piece before the
':' is quoted and the subsequent pieces are not.
<P>
A complete discussion of the available options for <var>mode</var> can 
be found in the online documentation in the book,
<B>I/O Devices Guide</B>, specifically the chapter on Sequential File I/O.

◆ ParentDirectoryName()

_.Library.String ParentDirectoryName ( _.Library.String  directory)
static

Given a directory name, return the name of its parent directory.


If the directory is already the root (e.g., "/" on Unix, "c:\" on Windows), return the root.

◆ RemoveDirectory()

_.Library.Boolean RemoveDirectory ( _.Library.String  name,
_.Library.Integer  return 
)
static

Removes directory name.

Returns true if it succeeds and false otherwise.

Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code.

◆ RemoveDirectoryTree()

_.Library.Boolean RemoveDirectoryTree ( _.Library.String  pTarget)
static

Recursively remove directory pTarget.

Returns true if it succeeds and false otherwise.

◆ Rename()

_.Library.Boolean Rename ( _.Library.String  oldname,
_.Library.String  newname,
_.Library.Integer  return 
)
static

Rename file oldname to newname.

Returns true if it succeeds and false otherwise.

The rename subfunction is only intended for changing the name of a regular file, not directories or other types of files. In particular, renaming a file across filesystems results in copying and deleting the original file, but this will not work for a directory. Renaming a directory within a file system does work. Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code.

◆ SHA1Hash()

_.Library.String SHA1Hash ( _.Library.String  file,
_.Library.Integer  type 
)
static

Return binary form of SHA1 hash on the file if type is 0 (the default).

If you want the string version then pass in type as 1. Note that if you already have the file open in this process calling this function will close this file.

◆ SetAttributes()

_.Library.Boolean SetAttributes ( _.Library.String  filename,
_.Library.String  attributes,
_.Library.Integer  return 
)
static

Set the OS specific attributes of the file.

See the Attribute method in this class for file attribute values. Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code.

◆ SetFileDateModified()

_.Library.Boolean SetFileDateModified ( _.Library.String  filename,
_.Library.TimeStamp  ntime,
_.Library.Boolean  utc,
_.Library.Integer  return 
)

Set the date last modified of file filename to be ntime in $H format.

By default ntime is local time. If you pass utc as true, ntime will be treated as UTC time. Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code.

◆ SetOwnerGroup()

_.Library.Status SetOwnerGroup (   filename,
  OwnerGroup 
)
static

Set the Owner and Group of a file or directory.


This uses the unix "chown" command to perform the operation, and is valid only on Unix platforms.

◆ SetReadOnly()

_.Library.Boolean SetReadOnly ( _.Library.String  filename,
_.Library.Boolean  leaveexisting,
_.Library.Integer  return 
)
static

Make this file/directory read only (if we can).

If leaveexisting is true then it will add read permissions to the file/directory without changing the existing permissions, by default it will remove all other permissions other than read only flags. The leaveexisting has no effect on Windows so you do not need to pass this argument on this platform. Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code.

◆ SetUMask()

_.Library.Integer SetUMask ( _.Library.Integer  NewMask)
static

Set umask to the given value and return the previous umask value.

Does not affect directories, which are always created with permission 775 (UMask 002) by default.

◆ SetWriteable()

_.Library.Boolean SetWriteable ( _.Library.String  filename,
_.Library.Boolean  writeonly,
_.Library.Integer  return 
)
static

Make this file/directory writable (if we can).

The writeonly

defaults to true in which case this makes the file write only, if you just want to add writable to the existing permissions without modifying the other permissions pass writeonly=0. The writeonly has no effect on Windows so you do not need to pass this argument on this platform. Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code.

◆ SubDirectoryName()

_.Library.String SubDirectoryName ( _.Library.String  directory,
_.Library.String  name,
_.Library.Boolean  normalized 
)
static

Given a directory name and the name of a sub directory create the name for the.

subdirectory inside the given directory. Return the new directory name. This is useful as the parsing of filenames on Unix/Windows is different.

◆ TempFilename()

_.Library.String TempFilename ( _.Library.String  ext,
_.Library.String  dir,
_.Library.Integer  return 
)
static

Return a temporary filename in the OS provided temp directory or the directory.

specified by dir.
If you specify ext the temp filename will have this extension.
Pass return by reference to obtain the low level return value in case of an error. It will be the negative value of the operating system return code, or 0 if there is no error.
In case of an error, the method returns an empty string.

◆ Truncate()

_.Library.Boolean Truncate ( _.Library.String  filename,
_.Library.Integer  return 
)
static

Truncate an existing file or create a new empty file.

Pass return by reference to obtain the low level return value in case of errors which is the negative value of the operating system return code.

Member Data Documentation

◆ SQLPUBLICSECURITY

SQLPUBLICSECURITY = None
static

For information on this class, see Using Library.File.

The <CLASS>File</CLASS> class represents a disk file. It contains a number of class methods that provide a number of file system services.

For example,

If ##class(File).Exists("file.txt") Write "It exists",!

You can also create an instance of a <CLASS>File</CLASS> object that represents a particular file. <CLASS>File</CLASS> makes a number of file attributes accessible as properties as well as providing a <CLASS>AbstractStream</CLASS> interface on the file.

For example,

Set file=##class(File).New("file.txt") Write file.Size Do file.Open("WSN") Do file.WriteLine("This is a line of text")

Note that this class is a fairly simple wrapper around the ObjectScript file commands. For simply reading/writing to a file it is suggested that you look at the <class>Stream.FileCharacter</class> and <class>Stream.FileBinary</class> classes. These open the file using the correct mode automatically in order to read or write to the file and so are simpler to use.

◆ CanonicalName

CanonicalName

Read only property that returns the canonical filename if the file is open and "" if the file is not open.

 

◆ DateCreated

DateCreated

The creation date for this file (rounded to the millisecond).

Only Windows

maintains the created date; other operating systems return the date of the last file "status" change.  

◆ DateModified

DateModified

The last modified date for this file (rounded to the millisecond).

 

◆ IsOpen

IsOpen

True (1) if this file is currently open, false (0) otherwise.

 

◆ Name

The name of this file.