DirectoryIterator_WIN32U.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // DirectoryIterator_WIN32U.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/DirectoryIterator_WIN32U.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Filesystem
  8. // Module: DirectoryIterator
  9. //
  10. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/DirectoryIterator_WIN32U.h"
  16. #if defined(_WIN32_WCE)
  17. #include "Poco/File_WINCE.h"
  18. #else
  19. #include "Poco/File_WIN32U.h"
  20. #endif
  21. #include "Poco/Path.h"
  22. #include "Poco/UnicodeConverter.h"
  23. #include <cstring>
  24. namespace Poco {
  25. DirectoryIteratorImpl::DirectoryIteratorImpl(const std::string& path): _fh(INVALID_HANDLE_VALUE), _rc(1)
  26. {
  27. Path p(path);
  28. p.makeDirectory();
  29. std::string findPath = p.toString();
  30. findPath.append("*");
  31. std::wstring uFindPath;
  32. UnicodeConverter::toUTF16(findPath, uFindPath);
  33. _fh = FindFirstFileW(uFindPath.c_str(), &_fd);
  34. if (_fh == INVALID_HANDLE_VALUE)
  35. {
  36. if (GetLastError() != ERROR_NO_MORE_FILES)
  37. File::handleLastError(path);
  38. }
  39. else
  40. {
  41. UnicodeConverter::toUTF8(_fd.cFileName, _current);
  42. if (_current == "." || _current == "..")
  43. next();
  44. }
  45. }
  46. DirectoryIteratorImpl::~DirectoryIteratorImpl()
  47. {
  48. if (_fh != INVALID_HANDLE_VALUE)
  49. FindClose(_fh);
  50. }
  51. const std::string& DirectoryIteratorImpl::next()
  52. {
  53. do
  54. {
  55. _current.clear();
  56. if (FindNextFileW(_fh, &_fd) != 0)
  57. {
  58. UnicodeConverter::toUTF8(_fd.cFileName, _current);
  59. }
  60. }
  61. while (_current == "." || _current == "..");
  62. return _current;
  63. }
  64. } // namespace Poco