Reputation: 3686
I am using the ZipArchive to unzip a zip file:
This file is a zipped up folder and i want to:
Make sure that the content consists of just a folder (obviously with files in side) Get the name of the unzipped folder so i can then rename it if needs be?
But having trouble getting the folders name after the unzip? I know i could get the name of the zip file as most of the time when zipped it the same name but some people also change the zipped file name.
Upvotes: 2
Views: 5719
Reputation: 53626
If you know for sure there's only one dir in the zip you can just do this:
$dir = trim($zip->getNameIndex(0), '/');
Otherwise, you'll have to loop over all the files and somehow figure out which one of them is the one you want:
for ($i = 0; $i < $zip->numFiles; $i++) {
$entry = $zip->getNameIndex($i);
}
Upvotes: 9