Skip to content

Instantly share code, notes, and snippets.

@dmentipl
Last active November 25, 2021 04:39
Show Gist options
  • Save dmentipl/f02badae3122305406865ceb30e6c00e to your computer and use it in GitHub Desktop.
Save dmentipl/f02badae3122305406865ceb30e6c00e to your computer and use it in GitHub Desktop.
Get the last .h5 snap in a dir (or list of dirs)
#!/usr/bin/env python3
import argparse
from pathlib import Path
def main():
parser = argparse.ArgumentParser(description='Last snap')
parser.add_argument('dirs', type=str, nargs='+', help='Input dirs for snaps')
args = parser.parse_args()
for d in args.dirs:
_d = Path(d)
if _d.exists():
try:
lastsnap = sorted(_d.glob('*.h5'))[-1].name
print(f'{d}/{lastsnap}')
except IndexError:
print(f'{d} contains no .h5 files')
else:
print(f'{d} does not exist')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment