-
cape.fileutils.get_latest_file(filelist: list) → str
Get the latest modified file from a list of files
- Call:
>>> fname = get_latest_file(filelist)
- Inputs:
- filelist:
list
[str
] List of file names
- Outputs:
- fname:
str
Name of latest modified file in list
- Version:
-
-
cape.fileutils.get_latest_regex(pat: str, baseglob=None)
Get the latest modified file matching a regular expression
- Call:
>>> fname, regmatch = get_latest_regex(pat, baseglob=None)
- Inputs:
- pat:
str
Regular expression string
- baseglob: {
None
} | str
Optional glob pattern to narrow candidates in current dir
- Outputs:
- fname:
str
Name of latest modified file in list
- regmatch:
re.Match
Regular expression groups, etc. for fname
- Version:
-
-
cape.fileutils.grep(pat: str, fname: str, encoding='utf-8') → list
Find lines of a file containing a regular expressoin
- Call:
>>> lines = grep(pat, fname, encoding="utf-8")
- Inputs:
- pat:
str
String of regular expression pattern
- fname:
str
Name of file to search
- encoding: {
"utf-8"
} | str
Encoding for file
- Outputs:
- lines:
list
[str
] List of lines containing a match of pat
- Versions:
-
-
cape.fileutils.head(fname: str, n=1, encoding='utf-8') → str
Get first n lines of a file
- Call:
>>> txt = head(fname, n=1)
- Inputs:
- fname:
str
Name of file to read
- n: {
1
} | int
Number of lines to read from beginning of file
- encoding: {
"utf-8"
} | str
Encoding for text file
- Versions:
-
-
cape.fileutils.sort_by_mtime(filelist: list) → list
Sort list of files by modification time (ascending)
- Call:
>>> tfiles = sort_by_mtime(filelist)
- Inputs:
- filelist:
list
[str
] List of file names
- Outputs:
- tfiles:
list
[str
] Files of filelist in order of ascending modification time
- Version:
-
-
cape.fileutils.tail(fname: str, n=1, encoding='utf-8')
Get last n lines of a file
- Call:
>>> txt = tail(fname, n=1)
- Inputs:
- fname:
str
Name of file to read
- n: {
1
} | int
Number of lines to read from end of file
- encoding: {
"utf-8"
} | str
Encoding for text file
- Outputs:
- txt:
str
Text of last n lines of fname
- Versions:
-
-
cape.fileutils.touch(fname: str)
Replicate touch
; creating new file or updating mod time
- Call:
-
- Inputs:
- fname:
str
Name of file to create/modify
- Versions:
-