Path
The Path object represents a file or folder path. Many objects have properties that return a Path - for example, Tab.path returns the current folder in a tab as a Path object. You can create a new Path object from a string (or another Path) using the DOpus.FSUtil.NewPath method.
<default value>
string
Returns the full path as a string.
components
int
Returns the number of components in the path.
disks
Vector:int
Returns a **Vector**of ints representing the physical disk drive or drives that this path resides on.
drive
int
Returns the drive number the path refers to (1=A, 2=B, etc.) or 0 if the path does not specify a drive. You can also change the drive letter of the path (while leaving the following path components alone) by modifying this value.
ext
string
Returns the filename extension of the path (the sub-string extending from the last . in the final component to the end of the string). This method does not check if the path actually refers to a file.
You can also change a path's file extension by setting this property (and strip the extension altogether by setting it to an empty string).
ext_m
string
Returns the filename extension of the path, taking multi-part extensions into account. For example, ext might return ".rar" whereas ext_m would return ".part1.rar".
You can't change the extension using ext_m, only ext.
filepart
string
Returns the filename part of the path (the last component).
longpath
*object:*Path
If this object represents a short pathname, this property returns the "long" equivalent.
pathpart
string
Returns the path minus the last component.
shortpath
*object:*Path
If this object represents a long pathname, this property returns the "short" equivalent, if it has one. Note that short paths are disabled by default in Windows 10.
stem
string
Returns the filename stem of the path (i.e. filepart minus ext).
stem_m
string
Returns the filename stem taking multi-part extensions into account. For example, stem might return "pictures.part1" whereas stem_m would return "pictures".
test_parent
bool
Returns True if a call to the Parent method would succeed.
test_root
bool
Returns True if a call to the Root method would succeed.
Method Name
Arguments
Return Type
Description
Add
<string:name> or <Vector:string>
none
Adds the specified name to the path (it will become the last component). As well as a string, you can pass a Vector of strings and all items in the vector will be added to the path.
Normalize
none
none
Normalizes the path by:
Converting all forward-slashes to back-slashes (or vice versa for a URL)
Collapsing duplicate slashes to a single slash (except where needed)
Normalize is automatically called when a new path string is assigned to a Path object so you don't normally need to call it manually.
Parent
none
bool
Removes the last component of the path. Returns False if the path does not have a valid parent.
ReplaceStart
<string:old> <string:new> <bool:wholepath>
bool
Compares the beginning of the path with the "old" string, and if it matches replaces it with the "new" string. The match is performed at the path component level - for example, an "old" string of "C:\Foo" would match the path "C:\Foo\Bar" but not "C:\FooBar". If the optional wholepath argument is set to True then the whole path must match rather than just its beginning. Returns True if the string matched the path or False otherwise.
Resolve
<string:flags>
none
Resolves the specified path string to its real filesystem path, with support for converting:
Folder Aliases to the real paths they point to.
Library and File Collection items to their real filesystem paths.
Application paths in the {apppath|appname} form.
Environment variables.
Optionally, junctions and symbolic links can be resolved to their targets. The Path object is modified in-place.
It is safe to pass a path which does not need resolving; the path will remain as-is, 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):
j
resolve junctions and symbolic links to their target folder
Note that DOpus.FSUtil has a similar Resolve method which takes a string input and returns a new Path object.
j
resolve junctions and symbolic links to their target folder
Root
none
bool
Strips off all but the first component of the path. Returns False if the path is already at the root.
Set
<string:path> or <Path:path> or <Vector:string>
none
Sets the path represented by the Path object to the specified string.
You can also set one Path object to the value of another. If you pass a Vector of strings the path will be built from the items in the vector.
Split
<int:first> <int:count>
Vector:string
Returns a Vector of strings representing the components of the path. For example, if the path is C:\Foo\Bar, the vector will contain three items - "C:\, "Foo" and "Bar". By default all components of the path are returned, but you can optionally provide the index of the first component and also the number of components to return.
ToUNC
none
bool
If the path begins with the drive letter of a mapped network drive, it will be converted into the UNC version of the path. For example, "X:\Test" may map to "\Server\Share\Test". Returns True if the path was modified and False if it was not.
最后更新于