Module containing file manipulation functions
Split the file name from its path, prepend the prefix to the file name and join it back
Parameters: | path : string
prefix : string
|
---|---|
Returns: | string
|
Examples
>>> prefix_filename('/path/to/file.dat', 'new_')
'/path/to/new_file.dat'
Generator that searches for and serves directories
Parameters: | path : string
matches : string or list of strings, optional
exclude : string or list of strings, optional
recursive : bool, optional
followlinks : bool, optional
|
---|---|
Returns: | dirname : string
|
Generator that search and serves files.
Parameters: | path : string
matches : string or list of strings, optional
exclude : string or list of strings, optional
exclude_dirs : string or list of strings, optional
recursive : bool, optional
followlinks : bool, optional
|
---|---|
Returns: | fn : string
Todo use Yields instead of Returns when the numpydoc 0.6 update will be available |
Skip commented lines and returns the file at the start of the first line without any
Parameters: | f : file object |
---|---|
Returns: | f : file object
|
Convert shell wildcard to regex
If wildcards is None, a match-nothing regex is used If wildcards is a list, the resulting regex are concatenated with | (or)
Parameters: | wildcards : None, string or list of strings
re_compile : bool, optional
|
---|---|
Returns: | regex : string or re.RegexObject
|
Examples
>>> wildcards_to_regex("[0-9]*fits")
"re.compile('[0-9].*fits\\Z(?ms)', re.MULTILINE|re.DOTALL)"
>>> wildcards_to_regex("[0-9]*fits", re_compile=False)
'[0-9].*fits\\Z(?ms)'
>>> wildcards_to_regex(None, re_compile=False)
'a^'
>>> wildcards_to_regex(["[0-3]*fits", "[5-9]*fits"], re_compile=False)
'[0-3].*fits\\Z(?ms)|[5-9].*fits\\Z(?ms)'