Path Tools

This module defines functions for handling files and paths.

gunzip(filename, outname=None)[source]

Returns output name that contains decompressed contents of filename. When no outname is given, filename is used as the output name as it is or after .gz extension is removed. filename may also be a string buffer, in which case decompressed string buffer or outname that contains buffer will be returned.

backupFile(filename, backup=None, backup_ext='.BAK', **kwargs)[source]

Rename filename with backup_ext appended to its name for backup purposes, if backup is True or if automatic backups is turned on using confProDy(). Default extension .BAK is used when one is not set using confProDy(). If filename does not exist, no action will be taken and filename will be returned. If file is successfully renamed, new filename will be returned.

openFile(filename, *args, **kwargs)[source]

Open filename for reading, writing, or appending. First argument in args is treated as the mode. Opening .gz and .zip files for reading and writing is handled automatically.

  • backup (bool) – backup existing file using backupFile() when opening in append or write modes, default is obtained from package settings
  • backup_ext (str) – extension for backup file, default is .BAK
openDB(filename, *args)[source]

Open a database with given filename.

openSQLite(filename, *args)[source]

Returns a connection to SQLite database filename. If 'n' argument is passed, remove any existing databases with the same name and return connection to a new empty database.

openURL(url, timeout=5, **kwargs)[source]

Open url for reading. Raise an IOError if url cannot be reached. Small timeout values are suitable if url is an ip address. kwargs will be used to make urllib.request.Request instance for opening the url.

copyFile(src, dst)[source]

Returns dst, a copy of src.


Returns true if path is an executable.


Returns true if path is readable by the user.


Returns true if path is writable by the user.


Make all directories that does not exist in a given path.


Returns path on Windows, and relative path elsewhere.

sympath(path, beg=2, end=1, ellipsis='...')[source]

Returns a symbolic path for a long path, by replacing folder names in the middle with ellipsis. beg and end specified how many folder (or file) names to include from the beginning and end of the path.


This function is based on the example in:

pickle(obj, filename, protocol=2, **kwargs)[source]

Pickle obj using pickle.dump() in filename. protocol is set to 2 for compatibility between Python 2 and 3.

unpickle(filename, **kwargs)[source]

Unpickle object in filename using pickle.load().


Returns concatenation of ordered lists of paths matching patterns in pathnames.

addext(filename, extension)[source]

Returns filename, with extension if it does not have one.