remove_file.cpp 964 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/fs.h>
  5. #include<__vic/windows/wchar.h>
  6. #include<__vic/windows/throw_last_error.h>
  7. #include<windows.h>
  8. namespace __vic {
  9. //----------------------------------------------------------------------------
  10. void remove_file(const char *path)
  11. {
  12. if(!::DeleteFileW(windows::utf8to16(path)))
  13. windows::throw_last_error("DeleteFile");
  14. }
  15. //----------------------------------------------------------------------------
  16. bool remove_file_if_exists(const char *path)
  17. {
  18. if(::DeleteFileW(windows::utf8to16(path))) return true;
  19. DWORD err = ::GetLastError();
  20. if(err == ERROR_FILE_NOT_FOUND) return false;
  21. windows::throw_last_error("DeleteFile", err);
  22. }
  23. //----------------------------------------------------------------------------
  24. bool remove_file_nt(const char *path) noexcept
  25. {
  26. return ::DeleteFileW(windows::utf8to16(path));
  27. }
  28. //----------------------------------------------------------------------------
  29. } // namespace