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:
parts - a list of the components (cf fs.get_parts())
root - the drive or UNC server/share ending in a backslash unless a drive-relative path
filename - final component
name - same as filename (convenience)
dirname - all path components before the last
path - combination of root and dirname
an exception is FilePath is relative.
base - base part of filename (ie the piece before the dot)
ext - ext part of filename (ie the dot and the piece after)
Path | root | filename | name | dirname | path | parent | base | ext |
---|---|---|---|---|---|---|---|---|
\\abcd.txt | \\ab | d.txt | d.txt | c | \\abc | \\abc 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:\ta.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.