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 | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CancelWatchChanges |
<string:id> |
none |
Cancels folder or file change monitoring previously established by a call to the WatchChanges method. The id parameter is the ID you assigned to your watcher when it was created. |
||||||||||||||||||||||||||||
ComparePath |
<string:path1> |
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 zero or more of the following letters (case sensitive):
|
||||||||||||||||||||||||||||
DisplayName |
<string:path> |
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 zero or more of the following letters (case sensitive):
|
||||||||||||||||||||||||||||
Drives |
none |
Vector:Drive |
Returns a Vector of Drive objects, one for each drive on the system. |
||||||||||||||||||||||||||||
Exists |
<string:path> |
bool |
Returns True if the specified file, folder or device exists, or False otherwise. The optional flags parameter can be set to w to use wildcards in the final path component. |
||||||||||||||||||||||||||||
GetADSNames |
<string:path> |
object:StringSet |
Returns a StringSet containing the names of any alternate data streams (ADS) found for the specified file or folder. |
||||||||||||||||||||||||||||
GetErrorMsg |
<int:error> |
string |
Returns the localized text description for a system error code. |
||||||||||||||||||||||||||||
GetFolderPair |
<string:path> |
object:PairedFolder |
Returns the pair of the specified folder, if one exists. The optional flags are compared against the configured options for the pair; they let you control in which conditions the pair is returned, and how to handle it if the paired folder doesn't exist.
|
||||||||||||||||||||||||||||
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. |
||||||||||||||||||||||||||||
GetShellProperty |
<string:path> <string:property> or <Map:properties> |
variant |
Returns the value of one or more shell properties for the specified file. The file path must be provided as the first parameter. The second parameter can be the name (or PKEY) of a property to retrieve, in which case the property value will be returned. Alternatively, the second argument can be a Map object which lets you retrieve multiple properties at once. Each property you want to retrieve should be added to the Map with its name as a key, with an empty string as its value. The values in the Map will be replaced by the property values. The optional type argument is a string that lets you control how the properties are looked up by name (not case-sensitive):
If neither is specified, both raw and display names can match. Note that if a shell property is returned by the system as a SAFEARRAY type, it will be converted automatically to a Vector object. |
||||||||||||||||||||||||||||
GetShellPropertyList |
<string:pattern> |
object:ShellProperty |
Returns a Vector of ShellProperty objects which represents all the possible shell properties available on the system. You can optionally provide a wildcard pattern as the first argument - if you do, only properties whose names match the supplied pattern will be returned. The optional type argument is a string that lets you restrict the list of properties further (not case-sensitive):
If neither is specified, both raw and display names can match. Additional flags supported by the type argument are:
|
||||||||||||||||||||||||||||
GetSignature |
<string:path> |
object:Signature |
For files signed with an Authenticode certificate (usually .exe and .dll files), returns a Signature object describing the signature used to sign the file with. By default the signature won't be validated - the method will simply extract and return information about it. The optional verify parameter lets you verify the integrity of the file as well. Set this value to True to do a simple hash check (verifies the file has not been modified, but doesn't check the signature), or use the following flags to validate the signature as well as checking the file.
|
||||||||||||||||||||||||||||
GetTempDirPath |
<int:lifetime> |
object:Path |
Creates a temporary folder (with a unique name) and returns the path to it in a Path object. Temporary folders created with this method have a limited lifetime after which Opus will automatically delete them (it will also clean them up when it's shutdown and restarted). The default lifetime is 20 minutes; you can change this using the optional parameter. |
||||||||||||||||||||||||||||
GetTempFile |
<string:suffix> |
object:File |
Creates a temporary file and returns a File object ready to be written to. The returned object supports both reading and writing, without having to open the file a second time (although you can do that if it is easier). You can obtain the name of the file using the File.path property. An optional filename suffix can be specified; if not provided (or an empty string is passed), the default is ".tmp". An optional prefix can also be specified; if not provided (or an empty string is passed), the default is "dop". Between the suffix and prefix, Opus will insert additional characters into the name to ensure it is unique. As an example, DOpus.FSUtil.GetTempFilePath(".txt","cat-") might generate C:\Users\Leo\AppData\Local\Temp\cat-202106230928470962.txt for a file path. The optional flags parameter can include zero or more of these letters (not case-sensitive):
The read, write and deletion sharing modes affect what other processes are allowed to do while the file is still open. Once the file is closed (assuming it has not been auto-deleted), other processes are always free to read, write or delete the file. When delete-on-close is used, other things may not be able to open the file unless they specifically permit the file to be deleted at the time they open it. 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). |
||||||||||||||||||||||||||||
GetTempFilePath |
<string:suffix> |
object:Path |
Creates a temporary file (with a unique name) and returns the path to it in a Path object. An optional filename suffix can be specified; if not provided (or an empty string is passed), the default is ".tmp". An optional prefix can also be specified; if not provided (or an empty string is passed), the default is "dop". Between the suffix and prefix, Opus will insert additional characters into the name to ensure it is unique. As an example, DOpus.FSUtil.GetTempFilePath(".txt","cat-") might generate C:\Users\Leo\AppData\Local\Temp\cat-202106230928470962.txt for a file path. |
||||||||||||||||||||||||||||
GetType |
<string:path> |
string |
Returns a string indicating the item 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. This method is different to PathType which tells you the underlying "namespace" type rather than whether something is simply a file or a folder. |
||||||||||||||||||||||||||||
Hash |
<string:path> or <string:type> |
string or object:Vector |
Calculates a checksum for the specified file or Blob. You can also specify multiple types (e.g. "md5,sha1,sha256") at once, in which case the specified checksums will be calculated at the same time, and the result will be returned as a Vector of strings (in the same order as you requested them). Unlike the other algorithms, CRC32 is a concept rather than a well-defined standard. We have provided the three CRC32 implementations you're most likely to encounter:
Example (VBScript): DOpus.FSUtil.Hash("C:\Windows\Notepad.exe","md5") |
||||||||||||||||||||||||||||
NewFileAttr |
<attributes> |
object:FileAttr |
Creates a new FileAttr object, which represents file attributes. You can initialize the new object by passing either a string representing the attributes to turn on (e.g. "hsr") or another FileAttr object. If you don't pass a value, the new object will default to all attributes turned off. |
||||||||||||||||||||||||||||
NewFileSize |
<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, decimal, currency, another FileSize object, or a Blob containing exactly 1, 2, 4 or 8 bytes). You can use a hexadecimal string by pre-pending $ or 0x. Example (VBScript): DOpus.FSUtil.NewFileSize(1024) When only a size is specified, the result will be an unsigned value, which means it can represent larger size values but cannot represent negative values. To create a signed value instead, specify "s" as the first parameter and specify the size as the second parameter. This is case-sensitive; it must be a lowercase "s". Example (VBScript): DOpus.FSUtil.NewFileSize("s", -1024) |
||||||||||||||||||||||||||||
NewPath |
<string:path> |
object:Path |
Creates a new Path object initialised to the provided path string. |
||||||||||||||||||||||||||||
NewWild |
<string:pattern> |
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 on the returned object before using it. See the description of the Wild.Parse method for a list of the valid flags. |
||||||||||||||||||||||||||||
OpenFile |
<string:path> or <object:Blob> |
object:File |
Opens or creates a file and returns a File object that lets you access its contents as binary data. A File object is always returned, even if the file could not be opened. Check File.error on the returned object immediately after creating it to see if opening the file succeeded. Even if a file was not be opened, some of the returned object's methods may still work. For example, if a file exists but permissions block you from opening it, you may still be able to change its attributes, or vice versa. The first argument can be either:
When opening a Blob, the created object will always be in read-write mode and the rest of the parameters (mode and window/elevation) are not used and need not be specified. When opening a file, the optional mode parameter specifies how to open it (case sensitive):
When opening in write mode or read-write mode, you can specify additional mode flags that control how the file is created or opened (case sensitive):
The mode flags can also include these letters (case sensitive):
When opening an existing file which something else already flagged for deletion, including files already open in delete-on-close mode, the p (permit deletion) flag must be specified. Non-Windows filesystems may have different locking and sharing rules. Opus will pass the requested flags to them, but it is ultimately up to them how they behave. The optional third parameter takes either a window object or a string indicating elevation mode. This parameter influences the behavior of UAC elevation prompts (and potentially other user interface elements) that may be triggered when opening the file. It can be one of the following:
Example (VBScript): Set F = DOpus.FSUtil.OpenFile("C:\Test.txt","wrcf","NoElevate")
|
||||||||||||||||||||||||||||
PathType |
<string:path> |
string |
Returns a string indicating the underlying "namespace" type of the specified file path. Possible values are:
This method is different to GetType which tells you whether something is a file or a directory. |
||||||||||||||||||||||||||||
ReadDir |
<string:path> |
object:FolderEnum |
Returns a FolderEnum object that lets you enumerate the contents of the specified folder. The optional flags string can include zero or more flag characters (not case-sensitive):
If you don't need any flags, skip the second argument entirely. You may see older scripts pass True and False as the second argument, to turn recursion on and off; that is deprecated but remains supported for compatibility. |
||||||||||||||||||||||||||||
Resolve |
<string:path> |
object:Path |
Resolves the specified path string to its real filesystem path, with support for converting:
It is safe to pass a path which does not need resolving; the path will be returned unmodified, so you can call this on things without checking if it is needed first. Scripts which pass the current directory to external software should generally call Resolve on the path first, otherwise they risk passing aliases like /desktop to things which won't understand them. The optional flags string can include the following letter (not case-sensitive):
Note that Path objects also have a similar Resolve method which modifies them in-place. |
||||||||||||||||||||||||||||
SameDrive |
<string:path1> |
bool |
Returns True if the two specified paths both refer to the same drive or partition. The optional flags string can contain zero or more of the following letters (case sensitive):
When neither z nor Z are specified, archives are essentially treated like normal directories and will be considered on the "same drive" as any path pointing to the same drive the archive is on, including other archive paths on that drive. |
||||||||||||||||||||||||||||
WatchChanges |
<string:id> |
int |
Establish monitoring of a folder or file for changes. Returns 0 for success or an error code on failure. When a change occurs to a monitored file or folder, the script's OnFilesystemChange event is triggered. The id argument lets you provide an ID for this watcher that's used to identify it when changes occur. dir is the full path to a filesystem folder, or a file if the i flag is set. The optional flags are:
Use the CancelWatchChanges method to cancel monitoring. |