Filesystem.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (C) 2009-2020, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <anki/util/String.h>
  7. namespace anki
  8. {
  9. /// @addtogroup util_file
  10. /// @{
  11. /// Return true if a file exists
  12. Bool fileExists(const CString& filename);
  13. /// Get path extension.
  14. void getFilepathExtension(const CString& filename, StringAuto& out);
  15. /// Get path filename.
  16. /// On path/to/file.ext return file.ext
  17. void getFilepathFilename(const CString& filename, StringAuto& out);
  18. /// Return true if directory exists?
  19. Bool directoryExists(const CString& dir);
  20. /// Callback for the @ref walkDirectoryTree.
  21. /// @param filename The file or directory name.
  22. /// @param userData User data passed to walkDirectoryTree.
  23. /// @param isDirectory True if it's directory, false if it's regular file.
  24. using WalkDirectoryTreeCallback = Error (*)(const CString& filename, void* userData, Bool isDirectory);
  25. /// Walk a directory and it's subdirectories. Will walk and list all directories and files of a directory.
  26. ANKI_USE_RESULT Error walkDirectoryTree(const CString& dir, void* userData, WalkDirectoryTreeCallback callback);
  27. /// Equivalent to: rm -rf dir
  28. /// @param dir The directory to remove.
  29. /// @param alloc A temp allocator that this function requires.
  30. ANKI_USE_RESULT Error removeDirectory(const CString& dir, GenericMemoryPoolAllocator<U8> alloc);
  31. /// Equivalent to: mkdir dir
  32. ANKI_USE_RESULT Error createDirectory(const CString& dir);
  33. /// Get the home directory.
  34. /// Write the home directory to @a buff. The @a buffSize is the size of the @a buff. If the @buffSize is not enough the
  35. /// function will throw an exception.
  36. ANKI_USE_RESULT Error getHomeDirectory(StringAuto& out);
  37. /// Get the time the file was last modified.
  38. ANKI_USE_RESULT Error getFileModificationTime(CString filename, U32& year, U32& month, U32& day, U32& hour, U32& min,
  39. U32& second);
  40. /// @}
  41. } // end namespace anki