Skip to content

Commit

Permalink
Return the filename with suffix or file_extension (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
ka-sarthak authored Aug 19, 2024
1 parent 0feb567 commit e2e7fb6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/nomad_material_processing/solution/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ def create_unique_filename(
suffix: str = 'archive.json',
):
"""
Create a unique filename of the form '{prefix}_{iterator}'. If the filename already
exists, the iterator is incremented until a unique filename is found.
Create a unique filename of the form '{prefix}_{iterator}.{suffix}'. If the filename
already exists, the iterator is incremented until a unique filename is found.
Args:
archive: The archive object.
prefix: Part of the filename before the iterator. Default is 'Unnamed'.
suffix: Usually the file extension. Default is 'archive.json'.
"""
i = 0
template = lambda i: f'{prefix}_{i}'
if not archive.m_context.raw_path_exists(template(i) + f'.{suffix}'):
template = lambda i: f'{prefix}_{i}.{suffix}'
if not archive.m_context.raw_path_exists(template(i)):
return template(i)
while True:
i += 1
if not archive.m_context.raw_path_exists(template(i) + f'.{suffix}'):
if not archive.m_context.raw_path_exists(template(i)):
return template(i)

0 comments on commit e2e7fb6

Please sign in to comment.