| 1 | // | 
|---|---|
| 2 | // dir.cpp | 
| 3 | // | 
| 4 | // This sample demonstrates the DirectoryIterator, File and Path classes. | 
| 5 | // | 
| 6 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. | 
| 7 | // and Contributors. | 
| 8 | // | 
| 9 | // SPDX-License-Identifier: BSL-1.0 | 
| 10 | // | 
| 11 | |
| 12 | |
| 13 | #include "Poco/DirectoryIterator.h" | 
| 14 | #include "Poco/File.h" | 
| 15 | #include "Poco/Path.h" | 
| 16 | #include "Poco/DateTimeFormatter.h" | 
| 17 | #include "Poco/DateTimeFormat.h" | 
| 18 | #include "Poco/Exception.h" | 
| 19 | #include <iostream> | 
| 20 | |
| 21 | |
| 22 | using Poco::DirectoryIterator; | 
| 23 | using Poco::File; | 
| 24 | using Poco::Path; | 
| 25 | using Poco::DateTimeFormatter; | 
| 26 | using Poco::DateTimeFormat; | 
| 27 | |
| 28 | |
| 29 | int main(int argc, char** argv) | 
| 30 | { | 
| 31 | std::string dir; | 
| 32 | if (argc > 1) | 
| 33 | dir = argv[1]; | 
| 34 | else | 
| 35 | dir = Path::current(); | 
| 36 | |
| 37 | try | 
| 38 | { | 
| 39 | DirectoryIterator it(dir); | 
| 40 | DirectoryIterator end; | 
| 41 | while (it != end) | 
| 42 | { | 
| 43 | Path p(it->path()); | 
| 44 | std::cout << (it->isDirectory() ? 'd' : '-') | 
| 45 | << (it->canRead() ? 'r' : '-') | 
| 46 | << (it->canWrite() ? 'w' : '-') | 
| 47 | << ' ' | 
| 48 | << DateTimeFormatter::format(it->getLastModified(), DateTimeFormat::SORTABLE_FORMAT) | 
| 49 | << ' ' | 
| 50 | << p.getFileName() | 
| 51 | << std::endl; | 
| 52 | ++it; | 
| 53 | } | 
| 54 | } | 
| 55 | catch (Poco::Exception& exc) | 
| 56 | { | 
| 57 | std::cerr << exc.displayText() << std::endl; | 
| 58 | return 1; | 
| 59 | } | 
| 60 | |
| 61 | return 0; | 
| 62 | } | 
| 63 | 
