FSUtil

The FSUtil object provides several utility methods for dealing with the file system. It is obtained using the DOpus.FSUtil method.

 

Method Name

Arguments

Return Type

Description

ComparePath

<string:path1>
<string:path2>
<string:flags>

bool

Compares the two provided path strings for equality - returns True if the two paths are equal, or False if otherwise.

The optional flags parameter lets you modify the comparison behavior. This parameter is a string containing one or more of the following letters:

c - case sensitive (makes the comparison case sensitive)
p - parent (tests if path2 is a parent of, or equal to, path1)

DisplayName

<string:path>
<string:flags>

string

Retrieves the display name of a path. This is the form of a path that is intended to be displayed to the user, rather than used internally by Opus. For example, for a library path it will strip off the internal ?xxxxxxx notation that Opus uses to identify library member folders.

The optional flags parameter lets you modify the behavior. This parameter is a string containing one or more of the following letters:

e - for editing (returns a string designed for editing rather than for display)
f - file part (returns the display filename rather than the entire path)
r - resolve (resolves library paths to their underlying file system folder)

Exists

<string:path>

bool

Returns True if the specified file, folder or device exists, or False otherwise.

GetItem

<string:path>

object:Item 

Creates an Item object for the specified file path.

GetMetadata

<string:path>

object:Metadata 

Returns a Metadata object representing the metadata for the specified file.

GetType

<string:path>
<string:flags>

string

Returns a string indicating the type of the specified file path. The string will be either file, dir or invalid if the path doesn't exist. The optional flags argument is used to control the behavior with archives - normally an archive will be reported as dir, but if you specify "a" for the flags parameter it will be reported as file.

Hash

<string:path>
<string:type>

string or object:Vector 

Calculates a checksum for the specified file. By default the MD5 checksum is calculated. You can specify "sha" for the optional type parameter to calculate the SHA checksum. If you specify "md5,sha" as the type then both checksums will be calculated at the same time, and the result will be returned as a Vector of strings (the MD5 checksum will always be the first element).

NewFileSize

<string:"s">
<size>

object:FileSize 

Creates a new FileSize object, which makes it easier to handle 64 bit file sizes. You can initialize this with a number of data types (int, string, currency, or another FileSize object).

If the optional "s" flag is specified, the FileSize object will use a signed 64 bit value rather than unsigned.

NewPath

<string:path>

object:Path

Creates a new Path object initialised to the provided path string.

NewWild

<string:pattern>
<string:flags>
 

object:Wild 

Creates a new Wild object. If a pattern and flags are provided the pattern will be parsed automatically, otherwise you must call the Parse method to parse a pattern before using the object.

See the description of the Wild.Parse method for a list of the valid flags.

OpenFile

<string:path> or <object:Blob>
<string:mode>
<object:window>

object:File 

Opens or creates a file and returns a File object that lets you access its contents as binary data. You can pass a string or Path object representing a file to open, and you can also pass an existing Blob object to create a File object that gives you read/write stream access to a chunk of memory.

By default the file will be opened in read mode - specify "w" for the optional mode parameter to open the file in write mode. Note that you cannot both read and write with the same File object, unless it was opened on a Blob.

 

When opening in write mode, you can also specify optional flags that control how the file is opened:

wc - create a new file, only if it doesn't already exist.
wa - create a new file, always. If the file already exists it will be overwritten. (this is the default)
we - open existing file. The file will not be created if it doesn't already exist.
wo - open existing file. If the file doesn't exist it will be created.
wt - truncate existing file. If the file exists it will be truncated. The file will not be created if it doesn't already exist.

If you only want to make changes to a file's attributes without modifying its data you can also specify "m" to open it in modify mode.

The optional window parameter lets you associate the File object with a Tab or a Lister, which will be used if Opus needs to display any dialogs (e.g. a UAC elevation dialog).

ReadDir

<string:path>
<bool:recurse>

object:FolderEnum 

Returns a FolderEnum object that lets you enumerate the contents of the specified folder. Pass True for the optional recurse flag to recursively enumerate the folder (i.e. to enumerate the contents of all its sub-folders, and their sub-folders, and so on).

Resolve

<string:path>
<string:flags>

object:Path

Resolves the specified library or file collection path to its underlying file system path. This method can also be used to resolve a folder alias, as well as application paths in the form {apppath|appname}.

The optional flags are:

j - resolve junctions and links to their target folder

SameDrive

<string:path>
<string:flags>

bool

Returns True if this path refers to the same drive or partition as the supplied path. The optional flags are:

c - treat CD burning staging area as the CD itself
m - consider mount points
r - real paths only
u - compare user for FTP drives
z - consider zip folders
Z - consider zip folders (target)