Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

Path_utils.py 1.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  1. from pathlib import Path
  2. from scandir import scandir
  3. image_extensions = [".jpg", ".jpeg", ".png", ".tif", ".tiff"]
  4. def get_image_paths(dir_path):
  5. dir_path = Path (dir_path)
  6. result = []
  7. if dir_path.exists():
  8. for x in list(scandir(str(dir_path))):
  9. if any([x.name.lower().endswith(ext) for ext in image_extensions]):
  10. result.append(x.path)
  11. return result
  12. def get_image_unique_filestem_paths(dir_path, verbose=False):
  13. result = get_image_paths(dir_path)
  14. result_dup = set()
  15. for f in result[:]:
  16. f_stem = Path(f).stem
  17. if f_stem in result_dup:
  18. result.remove(f)
  19. if verbose:
  20. print ("Duplicate filenames are not allowed, skipping: %s" % Path(f).name )
  21. continue
  22. result_dup.add(f_stem)
  23. return result
  24. def get_all_dir_names_startswith (dir_path, startswith):
  25. dir_path = Path (dir_path)
  26. startswith = startswith.lower()
  27. result = []
  28. if dir_path.exists():
  29. for x in list(scandir(str(dir_path))):
  30. if x.name.lower().startswith(startswith):
  31. result.append ( x.name[len(startswith):] )
  32. return result
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...