filesystem module

Provides access to engine’s filesystem interface.

class filesystem.SeekType

Bases: enum

CURRENT = _filesystem.SeekType.CURRENT
HEAD = _filesystem.SeekType.HEAD
TAIL = _filesystem.SeekType.TAIL
names = {'CURRENT': _filesystem.SeekType.CURRENT, 'HEAD': _filesystem.SeekType.HEAD, 'TAIL': _filesystem.SeekType.TAIL}
values = {0: _filesystem.SeekType.HEAD, 1: _filesystem.SeekType.CURRENT, 2: _filesystem.SeekType.TAIL}
class filesystem.SourceFile

Bases: instance

static open((str)file_path[, (str)mode='rt'[, (str)path_id=None]]) SourceFile
__init__((object)arg1, (object)arg2) None
close((SourceFile)arg1) None
fileno((SourceFile)arg1) int
flush((SourceFile)arg1) None
isatty((SourceFile)arg1) bool
read((SourceFile)arg1[, (_engines._sound.Channel)size=-1]) object
readable((SourceFile)arg1) bool
readline((SourceFile)arg1[, (_engines._sound.Channel)size=-1]) object
readlines((SourceFile)arg1[, (_engines._sound.Channel)hint=-1]) list
save((SourceFile)arg1, (str)file_path) None
seek((SourceFile)arg1, (_engines._sound.Channel)offset[, (_engines._sound.Channel)whence=_filesystem.SeekType.HEAD]) None
seekable((SourceFile)arg1) bool
tell((SourceFile)arg1) int
truncate((SourceFile)arg1[, (_engines._sound.Channel)size=-1]) int
write((SourceFile)arg1, (object)arg2) None
writeable((SourceFile)arg1) bool
writelines((SourceFile)arg1, (list)arg2) None
property closed

None( (_filesystem.SourceFile)arg1) -> bool

property eof

None( (_filesystem.SourceFile)arg1) -> bool

property handle

None( (_filesystem.SourceFile)arg1) -> object

property size

None( (_filesystem.SourceFile)arg1) -> int

filesystem.is_vpk_file((str)arg1) bool
filesystem.source_file(file_path)[source]

Ensures that the given file has a visible name on the file system.

Note

If the file was packed in a VPK archive, it gets copied to a temporary file. Thus, modifying the file has no effect on the original file.

Example:

with source_file('credits.txt') as file_path:
    print('Visible path:', file_path)
    with open(file_path) as f:
        print('Content:', f.read())