MCPcopy Create free account
hub / github.com/aiekick/ImGuiFileDialog / ScanDirectory

Method ScanDirectory

ImGuiFileDialog.cpp:760–856  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

758 }
759
760 std::vector<IGFD::FileInfos> ScanDirectory(const std::string& vPath) override {
761 std::vector<IGFD::FileInfos> res;
762 struct dirent** files = nullptr;
763 size_t n = scandir(vPath.c_str(), &files, nullptr, //
764 [](const struct dirent** a, const struct dirent** b) { //
765 return strcoll((*a)->d_name, (*b)->d_name);
766 });
767 if (n && files) {
768 for (size_t i = 0; i < n; ++i) {
769 struct dirent* ent = files[i];
770 IGFD::FileType fileType;
771 switch (ent->d_type) {
772 case DT_DIR: fileType.SetContent(IGFD::FileType::ContentType::Directory); break;
773 case DT_REG: fileType.SetContent(IGFD::FileType::ContentType::File); break;
774#if defined(_IGFD_UNIX_) || (DT_LNK != DT_UNKNOWN)
775 case DT_LNK:
776#endif
777 case DT_UNKNOWN: {
778 struct stat sb = {};
779#ifdef _IGFD_WIN_
780 const auto wfpn = IGFD::Utils::UTF8Decode(vPath + ent->d_name);
781 if (!_wstati64(wfpn.c_str(), &sb)) {
782#else
783 const auto fpn = vPath + IGFD::Utils::GetPathSeparator() + ent->d_name;
784 if (!stat(fpn.c_str(), &sb)) {
785#endif
786 if (sb.st_mode & S_IFLNK) {
787 fileType.SetSymLink(true);
788 // by default if we can't figure out the target type.
789 fileType.SetContent(IGFD::FileType::ContentType::LinkToUnknown);
790 }
791 if (sb.st_mode & S_IFREG) {
792 fileType.SetContent(IGFD::FileType::ContentType::File);
793 break;
794 } else if (sb.st_mode & S_IFDIR) {
795 fileType.SetContent(IGFD::FileType::ContentType::Directory);
796 break;
797 }
798 }
799 break;
800 }
801 default: break; // leave it invalid (devices, etc.)
802 }
803 if (fileType.isValid()) {
804 IGFD::FileInfos _file;
805 _file.filePath = vPath;
806 _file.fileNameExt = ent->d_name;
807 _file.fileType = fileType;
808 res.push_back(_file);
809 }
810 }
811 for (size_t i = 0; i < n; ++i) {
812 free(files[i]);
813 }
814 free(files);
815 }
816 return res;
817 }

Callers

nothing calls this directly

Calls 5

scandirFunction · 0.85
statClass · 0.85
SetContentMethod · 0.80
SetSymLinkMethod · 0.80
isValidMethod · 0.80

Tested by

no test coverage detected