# FSUtil

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

<table data-header-hidden><thead><tr><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th></tr></thead><tbody><tr><td>Method Name</td><td><strong>Arguments</strong></td><td>Return Type</td><td>Description</td><td></td><td></td><td></td><td></td></tr><tr><td>CancelWatchChanges</td><td>&#x3C;string:id></td><td><em>none</em></td><td>Cancels folder or file change monitoring previously established by a call to the <strong>WatchChanges</strong> method. The <strong>id</strong> parameter is the ID you assigned to your watcher when it was created.</td><td></td><td></td><td></td><td></td></tr><tr><td>ComparePath</td><td>&#x3C;string:path1><br>&#x3C;string:path2><br>&#x3C;string:flags></td><td><em>bool</em></td><td><p>Compares the two provided path strings for equality - returns <strong>True</strong> if the two paths are equal, or <strong>False</strong> if otherwise.</p><p>The optional <strong>flags</strong> parameter lets you modify the comparison behavior. This parameter is a string containing zero or more of the following letters (case sensitive):</p><table><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><strong>c</strong></td><td>Makes the path comparison <strong>case sensitive</strong>.</td><td></td></tr><tr><td><strong>p</strong></td><td>Returns <strong>True</strong> if <em>path2</em> is equal to or a <strong>parent</strong> of <em>path1</em>.</td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td>DisplayName</td><td></td><td></td></tr></tbody></table><p>&#x3C;string:path><br>&#x3C;string:flags></p></td><td><em>string</em></td><td><p>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 <em>?xxxxxxx</em> notation that Opus uses to identify library member folders.</p><p>The optional <strong>flags</strong> parameter lets you modify the behavior. This parameter is a string containing zero or more of the following letters (case sensitive):</p><table><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><strong>e</strong></td><td>for editing (returns a string designed for editing rather than for display)</td><td></td></tr><tr><td><strong>f</strong></td><td>file part (returns the display filename rather than the entire path)</td><td></td></tr><tr><td><strong>r</strong></td><td>resolve (resolves library paths to their underlying file system folder)</td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td>Drives</td><td></td><td></td></tr></tbody></table><p><em>none</em></p></td><td><strong>Vector:</strong><a href="drive"><strong>Drive</strong></a></td><td>Returns a <a href="vector"><strong>Vector</strong></a> of <a href="drive"><strong>Drive</strong></a> objects, one for each drive on the system.</td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>c</strong></td><td>Makes the path comparison <strong>case sensitive</strong>.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>p</strong></td><td>Returns <strong>True</strong> if <em>path2</em> is equal to or a <strong>parent</strong> of <em>path1</em>.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>DisplayName</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>e</strong></td><td>for editing (returns a string designed for editing rather than for display)</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>f</strong></td><td>file part (returns the display filename rather than the entire path)</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>r</strong></td><td>resolve (resolves library paths to their underlying file system folder)</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Drives</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Exists</td><td>&#x3C;string:path><br>&#x3C;string:flags></td><td><em>bool</em></td><td><p>Returns <strong>True</strong> if the specified file, folder or device exists, or <strong>False</strong> otherwise.</p><p>The optional <em>flags</em> parameter can be set to <strong>w</strong> to use wildcards in the final path component.</p></td><td></td><td></td><td></td><td></td></tr><tr><td>GetADSNames</td><td>&#x3C;string:path></td><td><em>object:</em><a href="stringset"><strong>StringSet</strong></a></td><td>Returns a <a href="stringset"><strong>StringSet</strong></a> containing the names of any alternate data streams (ADS) found for the specified file or folder.</td><td></td><td></td><td></td><td></td></tr><tr><td>GetErrorMsg</td><td>&#x3C;int:error></td><td><em>string</em></td><td>Returns the localized text description for a system error code.</td><td></td><td></td><td></td><td></td></tr><tr><td>GetFolderPair</td><td>&#x3C;string:path><br>&#x3C;string:flags></td><td><em>object:</em><a href="pairedfolder"><strong>PairedFolder</strong></a></td><td><p>Returns the <a href="../../../preferences/preferences_categories/frequently_used_paths/paired_folders">pair</a> 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.</p><table><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><strong>d</strong></td><td>Default dual-display folder</td><td></td></tr><tr><td><strong>v</strong></td><td>Default Navigation Lock target</td><td></td></tr><tr><td><strong>n</strong></td><td>Turn on Navigation Lock automatically</td><td></td></tr><tr><td><strong>y</strong></td><td>Default Synchronize target</td><td></td></tr><tr><td><strong>l</strong></td><td>Always display primary folder at the left/top</td><td></td></tr><tr><td><strong>u</strong></td><td>Use path even if it doesn't exist</td><td></td></tr><tr><td><strong>i</strong></td><td>Ignore the pair</td><td></td></tr><tr><td><strong>g</strong></td><td>Go up to first existing parent</td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td>GetItem</td><td></td><td></td></tr></tbody></table><p>&#x3C;string:path></p></td><td><em>object</em>:<a href="item"><strong>Item</strong></a></td><td>Creates an <a href="item"><strong>Item</strong></a> object for the specified file path.</td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>d</strong></td><td>Default dual-display folder</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>v</strong></td><td>Default Navigation Lock target</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>n</strong></td><td>Turn on Navigation Lock automatically</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>y</strong></td><td>Default Synchronize target</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>l</strong></td><td>Always display primary folder at the left/top</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>u</strong></td><td>Use path even if it doesn't exist</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>i</strong></td><td>Ignore the pair</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>g</strong></td><td>Go up to first existing parent</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>GetItem</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>GetMetadata</td><td>&#x3C;string:path></td><td><em>object:</em><a href="metadata"><strong>Metadata</strong></a></td><td>Returns a <a href="metadata"><strong>Metadata</strong></a> object representing the metadata for the specified file.</td><td></td><td></td><td></td><td></td></tr><tr><td>GetShellProperty</td><td><p>&#x3C;string:path></p><p>&#x3C;string:property> or &#x3C;<a href="map"><strong>Map</strong></a>:properties><br>&#x3C;string:type></p></td><td><em>variant</em></td><td><p>Returns the value of one or more shell properties for the specified file.</p><p>The file path must be provided as the first parameter.</p><p>The second parameter can be the name (or PKEY) of a property to retrieve, in which case the property value will be returned.</p><p>Alternatively, the second argument can be a **<a href="map">Map</a>**object which lets you retrieve multiple properties at once. Each property you want to retrieve should be added to the **<a href="map">Map</a>**with its name as a key, with an empty string as its value. The values in the <strong>Map</strong> will be replaced by the property values.</p><p>The optional <strong>type</strong> argument is a string that lets you control how the properties are looked up by name (not case-sensitive):</p><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>R</strong></td><td>The first property whose raw name matches will be used.</td></tr><tr><td><strong>D</strong></td><td>The first property whose display name matches will be used.</td></tr></tbody></table><p>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 <a href="vector"><strong>Vector</strong></a> object.</p></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>R</strong></td><td>The first property whose raw name matches will be used.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>D</strong></td><td>The first property whose display name matches will be used.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>GetShellPropertyList</td><td>&#x3C;string:pattern><br>&#x3C;string:type></td><td><em>object:</em><a href="shellproperty"><strong>ShellProperty</strong></a></td><td><p>Returns a <a href="vector"><strong>Vector</strong></a> of <a href="shellproperty"><strong>ShellProperty</strong></a> objects which represents all the possible shell properties available on the system.</p><p>You can optionally provide a wildcard <em>pattern</em> as the first argument - if you do, only properties whose names match the supplied pattern will be returned.</p><p>The optional <strong>type</strong> argument is a string that lets you restrict the list of properties further (not case-sensitive):</p><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>R</strong></td><td>Property raw names must match the pattern.</td></tr><tr><td><strong>D</strong></td><td>Property display names must match the pattern.</td></tr></tbody></table><p>If neither is specified, both raw and display names can match.</p><p>Additional flags supported by the <strong>type</strong> argument are:</p><table><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><strong>V</strong></td><td>Restrict to viewable properties only. Viewable properties are those intended to be shown to the user - they're the same ones shown in Explorer's column chooser UI.</td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td>GetSignature</td><td></td><td></td></tr></tbody></table><p>&#x3C;string:path><br>[&#x3C;bool:verify> or<br>&#x3C;string:flags>]</p></td><td><em>object:</em><a href="signature"><strong>Signature</strong></a></td><td><p>For files signed with an Authenticode certificate (usually .exe and .dll files), returns a <a href="signature"><strong>Signature</strong></a> object describing the signature used to sign the file with.</p><p>By default the signature won't be validated - the method will simply extract and return information about it. The optional <strong>verify</strong> parameter lets you verify the integrity of the file as well. Set this value to <strong>True</strong> 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.</p><table><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td>n</td><td>No revocation check</td><td></td></tr><tr><td>c</td><td>Check final certificate in the chain for revocation</td><td></td></tr><tr><td>C</td><td>Check the entire chain for revocation</td><td></td></tr><tr><td>R</td><td>Check the entire chain excluding the root certificate</td><td></td></tr><tr><td>h</td><td>Hash-only check</td><td></td></tr><tr><td>l</td><td>Treat certificates as expired once their timestamp has elapsed</td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td>GetTempDirPath</td><td></td><td></td></tr></tbody></table><p>&#x3C;int:lifetime></p></td><td><em>object:</em><a href="path"><strong>Path</strong></a></td><td>Creates a temporary folder (with a unique name) and returns the path to it in a <a href="path"><strong>Path</strong></a> 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.</td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>R</strong></td><td>Property raw names must match the pattern.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>D</strong></td><td>Property display names must match the pattern.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>V</strong></td><td>Restrict to viewable properties only. Viewable properties are those intended to be shown to the user - they're the same ones shown in Explorer's column chooser UI.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>GetSignature</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>n</td><td>No revocation check</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>c</td><td>Check final certificate in the chain for revocation</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>C</td><td>Check the entire chain for revocation</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>R</td><td>Check the entire chain excluding the root certificate</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>h</td><td>Hash-only check</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>l</td><td>Treat certificates as expired once their timestamp has elapsed</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>GetTempDirPath</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>GetTempFile</td><td>&#x3C;string:suffix><br>&#x3C;string:prefix><br>&#x3C;string:flags><br>&#x3C;object:window></td><td><em>object:</em><a href="file"><strong>File</strong></a></td><td><p>Creates a temporary file and returns a <a href="file"><strong>File</strong></a> object ready to be written to.</p><p>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).</p><p>You can obtain the name of the file using the <a href="file"><strong>File</strong></a>.path property.</p><p>An optional filename <strong>suffix</strong> can be specified; if not provided (or an empty string is passed), the default is ".tmp".</p><p>An optional <strong>prefix</strong> can also be specified; if not provided (or an empty string is passed), the default is "dop".</p><p>Between the suffix and prefix, Opus will insert additional characters into the name to ensure it is unique.</p><p>As an example, <strong>DOpus.FSUtil.GetTempFilePath(".txt","cat-")</strong> might generate <em>C:\Users\Leo\AppData\Local\Temp\cat-202106230928470962.txt</em> for a file path.</p><p>The optional <strong>flags</strong> parameter can include zero or more of these letters (not case-sensitive):</p><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>d</strong></td><td>delete-on-close. File will be deleted automatically when closed.</td></tr><tr><td><strong>p</strong></td><td>permit deletion. Other processes can delete the file.</td></tr><tr><td><strong>r</strong></td><td>read shareable. Other processes can read the file.</td></tr><tr><td><strong>w</strong></td><td>write shareable. Other processes can write to the file.</td></tr></tbody></table><p>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.</p><p>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.</p><p>The optional <strong>window</strong> parameter lets you associate the <strong>File</strong> object with a <a href="tab"><strong>Tab</strong></a> or a <a href="lister"><strong>Lister</strong></a>, which will be used if Opus needs to display any dialogs (e.g. a UAC elevation dialog).</p></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>d</strong></td><td>delete-on-close. File will be deleted automatically when closed.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>p</strong></td><td>permit deletion. Other processes can delete the file.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>r</strong></td><td>read shareable. Other processes can read the file.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>w</strong></td><td>write shareable. Other processes can write to the file.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>GetTempFilePath</td><td>&#x3C;string:suffix><br>&#x3C;string:prefix></td><td><em>object:</em><a href="path"><strong>Path</strong></a></td><td><p>Creates a temporary file (with a unique name) and returns the path to it in a <a href="path"><strong>Path</strong></a> object.</p><p>An optional filename <strong>suffix</strong> can be specified; if not provided (or an empty string is passed), the default is ".tmp".</p><p>An optional <strong>prefix</strong> can also be specified; if not provided (or an empty string is passed), the default is "dop".</p><p>Between the suffix and prefix, Opus will insert additional characters into the name to ensure it is unique.</p><p>As an example, <strong>DOpus.FSUtil.GetTempFilePath(".txt","cat-")</strong> might generate <em>C:\Users\Leo\AppData\Local\Temp\cat-202106230928470962.txt</em> for a file path.</p></td><td></td><td></td><td></td><td></td></tr><tr><td>GetType</td><td>&#x3C;string:path><br>&#x3C;string:flags></td><td><em>string</em></td><td><p>Returns a string indicating the item type of the specified file path. The string will be either <strong>file</strong>, <strong>dir</strong> or <strong>invalid</strong> if the path doesn't exist.</p><p>The optional <strong>flags</strong> argument is used to control the behavior with archives. Normally, an archive will be reported as <strong>dir</strong>, but if you specify "<strong>a</strong>" for the flags parameter it will be reported as <strong>file</strong>.</p><p>This method is different to <strong>PathType</strong> which tells you the underlying "namespace" type rather than whether something is simply a file or a folder.</p></td><td></td><td></td><td></td><td></td></tr><tr><td>Hash</td><td><p>&#x3C;string:path> or<br>&#x3C;object:<a href="blob"><strong>Blob</strong></a>></p><p>&#x3C;string:type></p></td><td><em>string</em> or <em>object:</em><a href="vector"><strong>Vector</strong></a></td><td><p>Calculates a checksum for the specified file or <a href="blob"><strong>Blob</strong></a>.<br>By default, the MD5 hash is calculated, but you can use the optional <strong>type</strong> parameter to change the hash/checksum algorithm. Valid values are (not case-sensitive) <strong>md5</strong>, <strong>blake3</strong>, <strong>sha1</strong>, <strong>sha256</strong>, <strong>sha512</strong>, <strong>crc32</strong>, <strong>crc32_php</strong> and <strong>crc32_php_rev</strong>.</p><p>You can also specify multiple types (e.g. <em>"md5,sha1,sha256"</em>) at once, in which case the specified checksums will be calculated at the same time, and the result will be returned as a <a href="vector"><strong>Vector</strong></a> of <em>strings</em> (in the same order as you requested them).</p><p>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:</p><ul><li><em>CRC32</em> is most common in the Windows world and matches what tools like 7-Zip and PKZip call "CRC32", and what PHP calls "CRC32b".</li><li><em>CRC32_PHP</em> is less common and matches what BZIP2 uses and what PHP outputs by default.</li><li><em>CRC32_PHP_REV</em> is the same as <em>CRC32_PHP</em> but with the result's byte-order reversed, as output by some tools.</li></ul><p><em>Example (VBScript):</em></p><pre><code>DOpus.FSUtil.Hash("C:\Windows\Notepad.exe","md5")
</code></pre></td><td></td><td></td><td></td><td></td></tr><tr><td>NewFileAttr</td><td><em>&#x3C;attributes></em></td><td><em>object:</em><a href="fileattr"><strong>FileAttr</strong></a></td><td><p>Creates a new <a href="fileattr"><strong>FileAttr</strong></a> object, which represents file attributes.</p><p>You can initialize the new object by passing either a string representing the attributes to turn on (e.g. <em>"hsr"</em>) or another <a href="fileattr"><strong>FileAttr</strong></a> object. If you don't pass a value, the new object will default to all attributes turned off.</p></td><td></td><td></td><td></td><td></td></tr><tr><td>NewFileSize</td><td><em>&#x3C;size></em><br>or<br>&#x3C;string:"s"><br><em>&#x3C;size></em></td><td><em>object:</em><a href="filesize"><strong>FileSize</strong></a></td><td><p>Creates a new <a href="filesize"><strong>FileSize</strong></a> object, which makes it easier to handle 64 bit file sizes.</p><p>You can initialize this with a number of data types (<em>int</em>, <em>string</em>, <em>decimal</em>, <em>currency</em>, another <a href="filesize"><strong>FileSize</strong></a> object, or a <a href="blob"><strong>Blob</strong></a> containing exactly 1, 2, 4 or 8 bytes). You can use a hexadecimal string by pre-pending <strong>$</strong> or <strong>0x</strong>.</p><p><em>Example (VBScript):</em></p><pre><code>DOpus.FSUtil.NewFileSize(1024)
</code></pre><p>When only a size is specified, the result will be an <em>unsigned</em> value, which means it can represent larger size values but cannot represent negative values.</p><p>To create a <em>signed</em> value instead, specify "<strong>s</strong>" as the first parameter and specify the size as the second parameter. This is case-sensitive; it must be a lowercase "s".</p><p><em>Example (VBScript):</em></p><pre><code>DOpus.FSUtil.NewFileSize("s", -1024)
</code></pre></td><td></td><td></td><td></td><td></td></tr><tr><td>NewPath</td><td>&#x3C;string:path></td><td><em>object:</em><a href="path"><strong>Path</strong></a></td><td>Creates a new **<a href="path">Path</a>**object initialised to the provided path string.</td><td></td><td></td><td></td><td></td></tr><tr><td>NewWild</td><td>&#x3C;string:pattern><br>&#x3C;string:flags></td><td><em>object:</em><a href="wild"><strong>Wild</strong></a></td><td><p>Creates a new <a href="wild"><strong>Wild</strong></a> object.</p><p>If a <strong>pattern</strong> and <strong>flags</strong> are provided, the pattern will be parsed automatically; otherwise, you must call the <strong>Parse</strong> method on the returned object before using it.</p><p>See the description of the <a href="wild"><strong>Wild</strong></a><strong>.Parse</strong> method for a list of the valid flags.</p></td><td></td><td></td><td></td><td></td></tr><tr><td>OpenFile</td><td>&#x3C;string:path> or &#x3C;object:<a href="blob"><strong>Blob</strong></a>><br>&#x3C;string:mode><br>&#x3C;object:window> or &#x3C;string:elevation></td><td><em>object:</em><a href="file"><strong>File</strong></a></td><td><p>Opens or creates a file and returns a <a href="file"><strong>File</strong></a> object that lets you access its contents as binary data.</p><p>A <strong>File</strong> object is always returned, even if the file could not be opened. Check <strong>File.error</strong> on the returned object immediately after creating it to see if opening the file succeeded.</p><p>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.</p><p>The first argument can be either:</p><ul><li>A string or **<a href="path">Path</a>**object which specifies the file to open.</li><li>An existing **<a href="blob">Blob</a>**object to create a <a href="file"><strong>File</strong></a> object that gives you read/write stream access to a chunk of memory.</li></ul><p>When opening a <a href="blob"><strong>Blob</strong></a>, the created object will always be in <em>read-write mode</em> and the rest of the parameters (<strong>mode</strong> and <strong>window</strong>/<strong>elevation</strong>) are not used and need not be specified.</p><p>When opening a file, the optional <strong>mode</strong> parameter specifies how to open it (case sensitive):</p><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>r</strong></td><td><em>Read mode</em>. The file can be read but not written. (This is the default.)</td></tr><tr><td><strong>w</strong></td><td><em>Write mode</em>. The file can be written, but not read.</td></tr><tr><td><strong>rw</strong></td><td><em>Read-write mode</em>. The file can be read and written from the same object.</td></tr></tbody></table><p>When opening in <em>write mode</em> or <em>read-write mode</em>, you can specify additional <strong>mode</strong> flags that control how the file is created or opened (case sensitive):</p><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>c</strong></td><td>Create a new file, only if it doesn't already exist. The call will fail if the file already exists.</td></tr><tr><td><strong>a</strong></td><td>Create a new file, always. If the file already exists, it will be overwritten, i.e. truncated to zero length. (This is the default if <strong>w</strong> or <strong>rw</strong> are used on their own.)</td></tr><tr><td><strong>e</strong></td><td>Open existing file. The call will fail if the file does not already exist.</td></tr><tr><td><strong>o</strong></td><td>Open existing file. The file will be created if it does not exist.</td></tr><tr><td><strong>t</strong></td><td>Truncate existing file. If the file exists, it will be truncated to zero length. If the file doesn't exist, the call will fail.</td></tr></tbody></table><p>The <strong>mode</strong> flags can also include these letters (case sensitive):</p><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>d</strong></td><td>Delete-on-close. The file will be automatically deleted when closed. (If something else also has the file open, it won't be deleted until everything closes it.)</td></tr><tr><td><strong>f</strong></td><td>Force. Opus will clear the file's read-only attribute if it blocks opening the file for writing; otherwise, attempting to open a read-only file for writing will fail. For example, "<strong>wof</strong>" is like "<strong>wo</strong>" mode but also clears the read-only attribute.</td></tr><tr><td><strong>m</strong></td><td>Modify mode. Use this if you want to use the <strong>File</strong> object to read or modify the file's attributes, or get the file's size, without reading or writing the actual file contents.</td></tr><tr><td><strong>p</strong></td><td>Permit deletion. Other processes can delete the file before it has been closed, although any deletion will not take place until it is closed. Files opened via this method always permit other readers and writers.</td></tr><tr><td><strong>x</strong></td><td>(Opus 13.9.1 and above.) (Lowercase x.) Exclude other readers. While you have the file open, nothing else can open it for reading. If something else already has it open for reading, your request to open the file will fail. Has no effect on filesystems that don't support it.</td></tr><tr><td><strong>X</strong></td><td>(Opus 13.9.1 and above.) (Uppercase X.) Exclude other writers. While you have the file open, nothing else can open it for writing. If something else already has it open for writing, your request to open the file will fail. Has no effect on filesystems that don't support it.</td></tr></tbody></table><p>When opening an existing file which something else already flagged for deletion, including files already open in <em>delete-on-close</em> mode, the <strong>p</strong> (permit deletion) flag must be specified.</p><p>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.</p><p>The optional third parameter takes either a <strong>window</strong> object or a string indicating <strong>elevation</strong> 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:</p><ul><li>An Opus <a href="tab"><strong>Tab</strong></a> or <a href="lister"><strong>Lister</strong></a> object which UAC prompts will appear over if elevation is required and has not already been obtained.</li><li>The string "<strong>NoElevate</strong>" to prevent UAC elevation entirely when opening this file.</li><li>The string "<strong>ElevateNoAsk</strong>" to prevent UAC prompts while still gaining elevation if something else already got it (e.g. a previous <strong>OpenFile</strong> call).</li></ul><p><em>Example (VBScript):</em></p><pre><code>Set F = DOpus.FSUtil.OpenFile("C:\Test.txt","wrcf","NoElevate")
</code></pre></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>r</strong></td><td><em>Read mode</em>. The file can be read but not written. (This is the default.)</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>w</strong></td><td><em>Write mode</em>. The file can be written, but not read.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>rw</strong></td><td><em>Read-write mode</em>. The file can be read and written from the same object.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>c</strong></td><td>Create a new file, only if it doesn't already exist. The call will fail if the file already exists.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>a</strong></td><td>Create a new file, always. If the file already exists, it will be overwritten, i.e. truncated to zero length. (This is the default if <strong>w</strong> or <strong>rw</strong> are used on their own.)</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>e</strong></td><td>Open existing file. The call will fail if the file does not already exist.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>o</strong></td><td>Open existing file. The file will be created if it does not exist.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>t</strong></td><td>Truncate existing file. If the file exists, it will be truncated to zero length. If the file doesn't exist, the call will fail.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>d</strong></td><td>Delete-on-close. The file will be automatically deleted when closed. (If something else also has the file open, it won't be deleted until everything closes it.)</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>f</strong></td><td>Force. Opus will clear the file's read-only attribute if it blocks opening the file for writing; otherwise, attempting to open a read-only file for writing will fail. For example, "<strong>wof</strong>" is like "<strong>wo</strong>" mode but also clears the read-only attribute.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>m</strong></td><td>Modify mode. Use this if you want to use the <strong>File</strong> object to read or modify the file's attributes, or get the file's size, without reading or writing the actual file contents.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>p</strong></td><td>Permit deletion. Other processes can delete the file before it has been closed, although any deletion will not take place until it is closed. Files opened via this method always permit other readers and writers.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>x</strong></td><td>(Opus 13.9.1 and above.) (Lowercase x.) Exclude other readers. While you have the file open, nothing else can open it for reading. If something else already has it open for reading, your request to open the file will fail. Has no effect on filesystems that don't support it.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>X</strong></td><td>(Opus 13.9.1 and above.) (Uppercase X.) Exclude other writers. While you have the file open, nothing else can open it for writing. If something else already has it open for writing, your request to open the file will fail. Has no effect on filesystems that don't support it.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>PathType</td><td>&#x3C;string:path></td><td><em>string</em></td><td><p>Returns a string indicating the underlying "namespace" type of the specified file path. Possible values are:</p><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>shell</strong></td><td>The path refers to the Windows shell - e.g. a virtual folder like This PC</td></tr><tr><td><strong>filesys</strong></td><td>The path is a real filesystem path - e.g. C:\Windows</td></tr><tr><td><strong>ftp</strong></td><td>The path is an FTP path</td></tr><tr><td><strong>zip</strong></td><td>The path is a zip file</td></tr><tr><td><strong>mtp</strong></td><td>The path is an MTP path (i.e. a portable device like a phone or a tablet)</td></tr><tr><td><strong>lib</strong></td><td>The path is a library</td></tr><tr><td><strong>coll</strong></td><td>The path is a collection</td></tr><tr><td><strong>plugin</strong></td><td>The path is a plugin-provided namespace, most probably an archive (but not Zip)</td></tr></tbody></table><p>This method is different to <strong>GetType</strong> which tells you whether something is a file or a directory.</p></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>shell</strong></td><td>The path refers to the Windows shell - e.g. a virtual folder like This PC</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>filesys</strong></td><td>The path is a real filesystem path - e.g. C:\Windows</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>ftp</strong></td><td>The path is an FTP path</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>zip</strong></td><td>The path is a zip file</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>mtp</strong></td><td>The path is an MTP path (i.e. a portable device like a phone or a tablet)</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>lib</strong></td><td>The path is a library</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>coll</strong></td><td>The path is a collection</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>plugin</strong></td><td>The path is a plugin-provided namespace, most probably an archive (but not Zip)</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>ReadDir</td><td>&#x3C;string:path><br>&#x3C;string:flags></td><td><em>object:</em><a href="folderenum"><strong>FolderEnum</strong></a></td><td><p>Returns a <a href="folderenum"><strong>FolderEnum</strong></a> object that lets you enumerate the contents of the specified folder.</p><p>The optional <strong>flags</strong> string can include zero or more flag characters (not case-sensitive):</p><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>r</strong></td><td>Recursively enumerate the folder, listing the contents of the folder, its sub-folders, their sub-folders, and so on.</td></tr><tr><td><strong>l</strong></td><td>Skip links. Prevents the traversal of symbolic links and junctions when recursively enumerating folders.</td></tr><tr><td><strong>s</strong></td><td>Shell enumeration. Ask's the Windows Shell to enumerate non-filesystem folders. For example, the <em>Quick Access</em> folder on Windows 10 could be enumerated with <strong>ReadDir("/quickaccess","s")</strong>; it would not work without the "<strong>s</strong>" because Quick Access is not a real filesystem directory.</td></tr><tr><td><strong>p</strong></td><td>Suppress password dialogs from encrypted archives.</td></tr></tbody></table><p>If you don't need any flags, skip the second argument entirely. You may see older scripts pass <strong>True</strong> and <strong>False</strong> as the second argument, to turn recursion on and off; that is deprecated but remains supported for compatibility.</p></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>r</strong></td><td>Recursively enumerate the folder, listing the contents of the folder, its sub-folders, their sub-folders, and so on.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>l</strong></td><td>Skip links. Prevents the traversal of symbolic links and junctions when recursively enumerating folders.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>s</strong></td><td>Shell enumeration. Ask's the Windows Shell to enumerate non-filesystem folders. For example, the <em>Quick Access</em> folder on Windows 10 could be enumerated with <strong>ReadDir("/quickaccess","s")</strong>; it would not work without the "<strong>s</strong>" because Quick Access is not a real filesystem directory.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>p</strong></td><td>Suppress password dialogs from encrypted archives.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>Resolve</td><td>&#x3C;string:path><br>&#x3C;string:flags></td><td><em>object:</em><a href="path"><strong>Path</strong></a></td><td><p>Resolves the specified path string to its real filesystem path, with support for converting:</p><ul><li><a href="../../../basic_concepts/the_lister/navigation/aliases"><strong>Folder Aliases</strong></a> to the real paths they point to.</li><li><strong>Library</strong> and <strong>File Collection</strong> items to their real filesystem paths.</li><li>Application paths in the <strong>{apppath|</strong><em><strong>appname</strong></em><strong>}</strong> form.</li><li>Environment variables.</li><li>Optionally, <strong>junctions</strong> and <strong>symbolic links</strong> can be resolved to their targets.</li></ul><p>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.</p><p>Scripts which pass the current directory to external software should generally call Resolve on the path first, otherwise they risk passing aliases like <em>/desktop</em> to things which won't understand them.</p><p>The optional <strong>flags</strong> string can include the following letter (not case-sensitive):</p><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>c</strong></td><td>Return canonical paths. This will expand short filenames to their true long filename representation.</td></tr><tr><td><strong>j</strong></td><td>Resolve junctions and symbolic links to their target folder.</td></tr></tbody></table><p>Note that <a href="path"><strong>Path</strong></a> objects also have a similar <strong>Resolve</strong> method which modifies them in-place.</p></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>c</strong></td><td>Return canonical paths. This will expand short filenames to their true long filename representation.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>j</strong></td><td>Resolve junctions and symbolic links to their target folder.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>SameDrive</td><td>&#x3C;string:path1><br>&#x3C;string:path2><br>&#x3C;string:flags></td><td><em>bool</em></td><td><p>Returns <strong>True</strong> if the two specified paths both refer to the same drive or partition.</p><p>The optional <strong>flags</strong> string can contain zero or more of the following letters (case sensitive):</p><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>c</strong></td><td>Consider the <strong>CD burning staging area</strong> the same as the CD (or other writable optical media) itself.</td></tr><tr><td><strong>m</strong></td><td>Handle <strong>NTFS mount points</strong>. (Slower but more accurate if either path may be below a mount point which really points to a different drive.)</td></tr><tr><td><strong>r</strong></td><td>Real paths only. (Skip extra processing that is only useful for things like FTP sites and MTP devices.)</td></tr><tr><td><strong>s</strong></td><td>Test if paths point to the same drive via drive letters created by the Windows <strong>subst</strong> command.</td></tr><tr><td><strong>u</strong></td><td>Compare <strong>FTP users</strong>. (By default, FTP paths are considered the "same drive" if they point to the same FTP site. The <strong>u</strong> flag adds the requirement that both paths have the same user name.)</td></tr><tr><td><strong>z</strong></td><td>If <strong>path1</strong> is <em>inside</em> a Zip file or other archive, only consider <strong>path2</strong> on the "same drive" if it is the archive itself or is <em>inside</em> the same archive.</td></tr><tr><td><strong>Z</strong></td><td>If <strong>path1</strong> is <em>inside</em> a Zip file or other archive, only consider <strong>path2</strong> on the "same drive" if it is <em>inside</em> the same archive.</td></tr></tbody></table><p>When neither <strong>z</strong> nor <strong>Z</strong> 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.</p></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>c</strong></td><td>Consider the <strong>CD burning staging area</strong> the same as the CD (or other writable optical media) itself.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>m</strong></td><td>Handle <strong>NTFS mount points</strong>. (Slower but more accurate if either path may be below a mount point which really points to a different drive.)</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>r</strong></td><td>Real paths only. (Skip extra processing that is only useful for things like FTP sites and MTP devices.)</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>s</strong></td><td>Test if paths point to the same drive via drive letters created by the Windows <strong>subst</strong> command.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>u</strong></td><td>Compare <strong>FTP users</strong>. (By default, FTP paths are considered the "same drive" if they point to the same FTP site. The <strong>u</strong> flag adds the requirement that both paths have the same user name.)</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>z</strong></td><td>If <strong>path1</strong> is <em>inside</em> a Zip file or other archive, only consider <strong>path2</strong> on the "same drive" if it is the archive itself or is <em>inside</em> the same archive.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>Z</strong></td><td>If <strong>path1</strong> is <em>inside</em> a Zip file or other archive, only consider <strong>path2</strong> on the "same drive" if it is <em>inside</em> the same archive.</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>WatchChanges</td><td>&#x3C;string:id><br>&#x3C;string:path><br>&#x3C;string:flags></td><td><em>int</em></td><td><p>Establish monitoring of a folder or file for changes. Returns <strong>0</strong> for success or an error code on failure.</p><p>When a change occurs to a monitored file or folder, the script's <a href="../scripting_events/onfilesystemchange">OnFilesystemChange</a> event is triggered.</p><p>The <strong>id</strong> argument lets you provide an ID for this watcher that's used to identify it when changes occur. <strong>dir</strong> is the full path to a filesystem folder, or a file if the <strong>i</strong> flag is set.</p><p>The optional flags are:</p><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>f</strong></td><td>monitor for file change in folder (e.g. file created)</td></tr><tr><td><strong>d</strong></td><td>monitor for directory change in folder (e.g. directory created)</td></tr><tr><td><strong>r</strong></td><td>recursive - monitor sub-folders</td></tr><tr><td><strong>a</strong></td><td>monitor for file attribute changes</td></tr><tr><td><strong>s</strong></td><td>monitor for file size changes</td></tr><tr><td><strong>w</strong></td><td>monitor for last write time changes</td></tr><tr><td><strong>i</strong></td><td>monitor a single file rather than a folder</td></tr></tbody></table><p>Use the <strong>CancelWatchChanges</strong> method to cancel monitoring.</p></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>f</strong></td><td>monitor for file change in folder (e.g. file created)</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>d</strong></td><td>monitor for directory change in folder (e.g. directory created)</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>r</strong></td><td>recursive - monitor sub-folders</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>a</strong></td><td>monitor for file attribute changes</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>s</strong></td><td>monitor for file size changes</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>w</strong></td><td>monitor for last write time changes</td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td><strong>i</strong></td><td>monitor a single file rather than a folder</td><td></td><td></td><td></td><td></td><td></td><td></td></tr></tbody></table>
