On Wednesday, 12 February 2020 at 05:59:53 UTC, cc wrote:
On Monday, 3 February 2020 at 13:26:38 UTC, mark wrote:
I'm using std.zip.ZipArchive to read zip files, e.g.:
[snip]
I couldn't find one either, I had to do this:
version(Windows) {
enum uint FILE_ATTRIBUTE_DIRECTORY = 0x10;
}
auto zip = new ZipArchive(buffer);
foreach (fn, am; zip.directory) {
if (am.fileAttributes & FILE_ATTRIBUTE_DIRECTORY)
... is directory
else
... is file
}
I need to work on both Linux and Windows, and on Linux
am.fileAttributes seems to be 0 for both files and directories.
The lack of a cross-platform way of distinguishing whether an
archive member is a directory or file does seem to be a missing
piece of the API.
As I'm looking at my code for this I'm also reminded that
different zip files can internally store path separators as
either \ or / depending on the platform that created them so
you may need to be careful about that too. I have a bit for
this that simply does:
version(StandardizePathSeparators) {
string filename = fn.replace("\\", "/");
} else {
string filename = fn;
}
Yes, I was aware of that, but I use:
string filename = fn.tr("\\", "/"); // tr is from std.string