Use the right API for iterating a directory
Summary:
Use DirEntries instead of constructing paths and request data randomly
makes the script a bit faster and the code easier to read.
Test Plan:
Works here, didn't work in the CI, I don't understand why.
https://build.kde.org/job/Frameworks%20kfilemetadata%20kf5-qt5%20FreeBSDQt5.10/6/
Reviewers: Sysadmin
Differential Revision: https://phabricator.kde.org/D12850