Information about content in folders. (Windows)

For example, when hovering over a file in c:\, a file description will quickly display that includes the file type, size, and date. Now I wonder if there is a function that can give me all the same information through a single call, or at least something nearby.

I also wonder if there is a function/method that can give me the correct filetype? At the moment I use the extension to figure it out, which may be ".jpg" but the type itself is ".jpeg".

Same thing with ".log", which have the type of "textdocument" in windows
Hello Mikey. Thank you for your suggestion. I tested GetFileAttributesA() earlier to determine whether an address is a file or folder. Usually it returns 32 for ordinary files, or 16 for folders. But often it also returns many other values ​​for different types of folders such as system folders, etc. This makes it difficult to check if an address is a folder through the return value.
these values are bit masks, the values identified here https://docs.microsoft.com/en-gb/windows/desktop/FileIO/file-attribute-constants should be OR'd together.

therefore you need to test the bits rather than the entire value...
bool isDir = (GetFileAttributesA("myfile") & FILE_ATTRIBUTE_DIRECTORY != 0);
As much as you may think boost is evil, in these cases where the standard library will not help you boost can be helpful, and boost filesystem is the most robust solution to this problem (also if you have the slightest, teeniest desire to write cross platform code, the easiest way to learn it is to start early).

If all you need is to get is the simple file information, you can use this incredibly minimal cut out from boost filesystems "path" object here:
https://github.com/wjakob/filesystem

With this you can get the file size, the extension, the absolute path, and that's about it.

And the best part is that filesystem is moving into standard C++ eventually, I'm quite sure that all the actively developed compilers has some sort of experimental version of the filesystem library.
Filesystem is moving into standard C++ eventually

Eventually? It's already been added as part of C++17.
https://en.cppreference.com/w/cpp/filesystem
My eyes shined when I heard you say that, and I immediately I tried the experimental version on my mingw-w64 7.3 (there probably is a newer vesion of mingw that has a full version of c++17, anyways), I found that its filesystem has the exact same problem that mingw-w64's streams have, which is the fact that utf-8 unicode filesystem names just do not compute...

I actually use boost memory mapped files just to avoid that problem...

Oh well, I guess it is relatively easy to port mingw code to clang, so that could be a solution...
Topic archived. No new replies allowed.