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> |
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. |
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. |
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:type> |
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):
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):
|
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 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> or |
string or object:Vector |
Calculates a checksum for the specified file or Blob. By default, the MD5 hash is calculated, but you can use the optional type parameter to change the hash/checksum algorithm. Valid values are (not case-sensitive):
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> or <string:"s"> |
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):
Files opened via this method always permit other readers and writers. Your script should not assume it has an exclusive lock on the file or its contents. 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): |
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 it. The optional flags string can include the following letter (not case-sensitive):
|
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. |