campy.io.filelib module

This file exports a standardized set of tools for working with files. The library offers at least some portability across the file systems used in the three supported platforms: Mac OSX, Windows, and Linux. Directory and search paths are allowed to contain separators in any of the supported styles, which usually makes it possible to use the same code on different platforms.

Note: Several of the functions that lived in CPP’s version of this library are removed, to force students to learn the proper builtin pathlib library. The compatability is listed here:

def create_directory(path):
    _Path(path).mkdir()

def create_directory_path(path):
    _Path(path).mkdir(path, parents=True)

def default_extension(path, ext):
    p = _Path(path)
    if ext.startswith('*') or not p.suffix:
        return p.with_suffix(ext)

def delete_file(path):
    return os.remove(path)

TODO more

campy.io.filelib.expand_pathname(path)[source]
campy.io.filelib.file_exists(path)[source]
campy.io.filelib.find_on_path(path, filename)[source]
campy.io.filelib.get_current_directory()[source]
campy.io.filelib.get_directory_path_separator()[source]
campy.io.filelib.get_extension(path)[source]
campy.io.filelib.get_head(path)[source]
campy.io.filelib.get_root(path)[source]
campy.io.filelib.get_search_path_separator(path)[source]
campy.io.filelib.get_tail(path)[source]
campy.io.filelib.get_temp_directory()[source]
campy.io.filelib.is_directory(path)[source]
campy.io.filelib.is_file(path)[source]
campy.io.filelib.list_directory(path)[source]
campy.io.filelib.match_filename_pattern(path)[source]
campy.io.filelib.open_file(path)[source]
campy.io.filelib.open_file_dialog(title='Open File', mode='load', path='', binary=False)[source]

Opens a dialog that allows the user to choose the file. The title parameter is displayed in the dialog title. The path parameter is used to set the working directory; if path does not appear, openFileDialog uses the current directory.

@type title: string @param title: title of dialog box @type mode: string @param mode: mode of dialog box @type binary: boolean @param binary: open file in binary mode on windows @rtype: file

campy.io.filelib.open_on_path(path)[source]
campy.io.filelib.prompt_user_for_file(prompt='', reprompt='')[source]
campy.io.filelib.read_entire_file(stream, lines)[source]
campy.io.filelib.rename(old, new)[source]
campy.io.filelib.rewindStream(input)[source]
campy.io.filelib.set_current_directory(path)[source]
campy.io.filelib.write_entire_file(path)[source]