%Library.File
stream class %Library.File extends %Library.AbstractStream
The %File 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 %File object that represents a particular file. %File makes a number of file attributes accessible as properties as well as providing a %AbstractStream 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")
Property Inventory
Method Inventory
- Attributes()
- CanonicalFilename()
- CanonicalNameGet()
- Clear()
- Close()
- Compare()
- ComplexDelete()
- ComputeFullDBDir()
- CopyDir()
- CopyFile()
- CopyFromAndSave()
- CreateDirectory()
- CreateDirectoryChain()
- CreateNewDir()
- DateCreatedGet()
- DateModifiedGet()
- Delete()
- DirectoryExists()
- DriveListClose()
- DriveListExecute()
- DriveListFetch()
- Exists()
- FileSetClose()
- FileSetExecute()
- FileSetFetch()
- GetDirectory()
- GetDirectoryLength()
- GetDirectoryPiece()
- GetDirectorySpace()
- GetFileDateCreated()
- GetFileDateModified()
- GetFileSize()
- GetFilename()
- LastModifiedGet()
- ManagerDirectory()
- NormalizeDirectory()
- NormalizeFilename()
- NormalizeFilenameWithSpaces()
- Open()
- ParentDirectoryName()
- ParseDirectoryClose()
- ParseDirectoryExecute()
- ParseDirectoryFetch()
- Read()
- ReadOnly()
- RemoveDirectory()
- RemoveDirectoryTree()
- Rename()
- Rewind()
- SHA1Hash()
- SetAttributes()
- SetReadOnly()
- SetUMask()
- SetWriteable()
- SizeGet()
- SubDirectoryName()
- TempFilename()
- VMSRecordFormat()
- Write()
- WriteLine()
- Writeable()
Properties
Methods
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
On OpenVMS, this is the file protection presented
as four 4-bit fields, accessed by the following hexadecimal masks:
- 000F: system privileges
- 00F0: owner privileges
- 0F00: group privileges
- F000: world privileges
- 1: no read access
- 2: no write access
- 4: no execute access
- 8: no delete access
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.
Returns a %Status value indicating success or failure.
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.
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
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.
Parameter
pathname : A filename or pathname, specified as a quoted string. You cannot supply a Windows pathname as a doubly-quoted string.
Description
The NormalizeFilenameWithSpaces class method handles spaces in pathnames as appropriate to the host platform. If the pathname contains a space character, pathname handling is platform-dependent.
OpenVMS permits space characters in pathnames; NormalizeFilenameWithSpaces performs no special processing and returns the pathname unchanged.
UNIX only permits space characters in quoted pathnames; if a pathname containing spaces NormalizeFilenameWithSpaces returns the pathname enclosed in double quotes ("pathname"). If a pathname does not contain spaces, the method returns it unchanged. NormalizeFilenameWithSpaces performs no other pathname validation.
On Windows systems, NormalizeFilenameWithSpaces strips spaces from the supplied pathname of an existing file. If a pathname does not contain spaces, the method returns it unchanged in all cases. On Windows systems, the method validates pathnames that contain spaces. If a pathname containing spaces does not exist, NormalizeFilenameWithSpaces returns the pathname unchanged (with its blank spaces), with the entire pathname enclosed in double quotes ("pathname"). If a pathname containing spaces exists, the method returns the short form pathname with spaces removed, such as the following:
WRITE ##class(%File).NormalizeFilenameWithSpaces("C:\My Test File.txt") C:\MYTEST~1.TXT
NormalizefilenameWithSpaces is commonly used with the $ZF(-1) and $ZF(-2) functions.
mode is a string containing one or more file modes including:
R | Read |
W | Write |
S | Stream mode |
N | Create a new file (overwrite existing file) |
A complete discussion of the available options for mode can be found in the online documentation in the book, Caché I/O Devices Guide, specifically the chapter on Sequential File I/O.
If the directory is already the root (e.g., "/" on Unix, "c:\" on Windows or "dka1:" on VMS), return the root.
Queries
- Windows: return a list of available drives
- Unix: return a list of mounted file systems
- VMS: return a list of available disk devices
- Name - the name of the file (the default)
- Type - file type
- DateCreated - the date the file was created (rounded to second)
- DateModified - the date the file was last modified (rounded to second)
- Size - the file size
Inherited Members
Inherited Properties
Inherited Methods
- %AddToSaveSet()
- %CheckUnique()
- %ClassIsLatestVersion()
- %ClassName()
- %ConstructClone()
- %Delete()
- %DeleteExtent()
- %DeleteId()
- %DispatchClassMethod()
- %DispatchGetModified()
- %DispatchGetProperty()
- %DispatchMethod()
- %DispatchSetModified()
- %DispatchSetMultidimProperty()
- %DispatchSetProperty()
- %Exists()
- %ExistsId()
- %Extends()
- %GetParameter()
- %GetSwizzleObject()
- %Id()
- %IsA()
- %IsModified()
- %IsNull()
- %KillExtent()
- %LOBPrefetch()
- %LocationSet()
- %LockStream()
- %New()
- %NormalizeObject()
- %ObjectIsNull()
- %ObjectModified()
- %ObjectSize()
- %Oid()
- %Open()
- %OpenId()
- %OriginalNamespace()
- %PackageName()
- %ReleaseLock()
- %Reload()
- %RemoveFromSaveSet()
- %RollBack()
- %Save()
- %SerializeObject()
- %SetModified()
- %UnlockStream()
- %ValidateObject()
- CopyFrom()
- DeleteAttribute()
- DeleteStream()
- FindAt()
- Flush()
- GetAttribute()
- GetAttributeList()
- GetStreamId()
- InputFromDevice()
- IsCharacter()
- IsDefinedAttribute()
- IsNull()
- LineTerminatorSet()
- MoveTo()
- MoveToEnd()
- NextAttribute()
- OpenStream()
- OutputToDevice()
- OutputToDeviceAt()
- ReadLine()
- ReadLineIntoStream()
- ReadSQL()
- SaveStream()
- SerializeToSyncSet()
- SetAttribute()
- SetAttributeList()
- StreamOIDIsNull()
- SyncStreamIn()