{ } Raw JSON

bundles / traitlets latest / traitlets / utils / filefind

function

traitlets.utils:filefind

source: /traitlets/utils/__init__.py :15

Signature

def   filefind ( filename : str path_dirs : Sequence[str] | None = None )  →  str

Summary

Find a file by looking through a sequence of paths.

Extended Summary

This iterates through a sequence of paths looking for a file and returns the full, absolute path of the first occurrence of the file. If no set of path dirs is given, the filename is tested as is, after running through expandvars and expanduser. Thus a simple call

filefind('myfile.txt')

will find the file in the current working dir, but

filefind('~/myfile.txt')

Will find the file in the users home directory. This function does not automatically try any paths, such as the cwd or the user's home directory.

Parameters

filename : str

The filename to look for.

path_dirs : str, None or sequence of str

The sequence of paths to look for the file in. If None, the filename need to be absolute or be in the cwd. If a string, the string is put into a sequence and the searched. If a sequence, walk through each element and join with filename, calling expandvars and expanduser before testing for existence.

Returns

: Raises :exc:`IOError` or returns absolute path to file.

Aliases

  • traitlets.utils.filefind