Mercurial > libervia-backend
comparison sat/tools/common/files_utils.py @ 3131:d6da17f6e4ce
tools (common/files_utils): fixed get_unique_name when `path` is a str and not a Path
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 27 Jan 2020 19:53:31 +0100 |
parents | 2e1c3d33099b |
children | 9d0df638c8b4 |
comparison
equal
deleted
inserted
replaced
3130:b9486a7f9b4f | 3131:d6da17f6e4ce |
---|---|
25 """Generate a path with a name not conflicting with existing file | 25 """Generate a path with a name not conflicting with existing file |
26 | 26 |
27 @param path(str, Path): path to the file to create | 27 @param path(str, Path): path to the file to create |
28 @return (Path): unique path (can be the same as path if there is no conflict) | 28 @return (Path): unique path (can be the same as path if there is no conflict) |
29 """ | 29 """ |
30 ori_path = Path(path) | 30 ori_path = path = Path(path) |
31 idx = 1 | 31 idx = 1 |
32 while path.exists(): | 32 while path.exists(): |
33 path = ori_path.with_name(ori_path.name + f"_{idx}") | 33 path = ori_path.with_name(ori_path.name + f"_{idx}") |
34 idx += 1 | 34 idx += 1 |
35 return path | 35 return path |