Bases: unicode
A unicode subtype which knows about path structures on Windows. The path itself need not exist on any filesystem, but it has to match the rules which would make it possible.
FilePaths can be absolute or relative. The only difference is that the root attribute is empty for relative paths. They can be added to each other or to other unicode strings which will use os.path.join semantics.
A FilePath offers quick access to the different parts of the path:
Path | root | filename | name | dirname | path | parent | base | ext |
---|---|---|---|---|---|---|---|---|
\\a\b\c\d.txt | \\a\b\ | d.txt | d.txt | c | \\a\b\c | \\a\b\c | d | .txt |
c:\boot.ini | c:\ | boot.ini | boot.ini | _ | c:\ | c:\ | boot | .ini |
boot.ini | _ | boot.ini | boot.ini | _ | _ | x_fs | boot | .ini |
c:\t | c:\ | t | t | _ | c:\ | c:\ | t | _ |
c:\t\ | c:\ | t | t | _ | c:\ | c:\ | t | _ |
c:\t\a.txt | c:\ | a.txt | a.txt | t | c:\t | c:\t | a | .txt |
c:a.txt | c: | a.txt | a.txt | _ | c: | x_fs | a | .txt |
a.txt | _ | a.txt | a.txt | _ | _ | x_fs | a | .txt |
Return an absolute version of the current FilePath, whether relative or not. Use os.path.abspath() semantics.
Return an absolute version of the current FilePath, whether relative or not. Use os.path.abspath() semantics.
Return a new FilePath with one or more parts changed. This is particularly convenient for, say, changing the extension of a file or producing a version on another path, eg:
from winsys import fs, shell
BACKUP_DRIVE = "D:\"
for f in fs.flat (shell.special_folder ("personal"), "*.doc"):
f.copy (f.changed (root=BACKUP_DRIVE))
Designed to be redefined in a subclass so that the __add__() and __radd__() methods can return the appropriate type.
Recreate a filepath from its constituent parts. No real validation is done; it is assumed that the parameters are valid parts of a filepath.
A filepath is relative if it has no root or if its root is a drive letter only (without a directory backslash).
Return this filepath as relative to another. cf utils.relative_to()