0

I tried to use the ZipArchive framework for unzipping a zip file, but I don't understand the problem. It doesn't tell me some error, but I could not find my unzipped files/folders.

// Unzip
let sourceURL = localUrl.stringByAppendingPathComponent(path: "TEMP.zip")
let destinationURL = localUrl.stringByAppendingPathComponent(path: "TEST")
SSZipArchive.unzipFile(atPath: sourceURL, toDestination: destinationURL)

EDIT: With the answer above, here is the error message:
Error Message: Error Domain=SSZipArchiveErrorDomain Code=-1 "failed to open zip file" UserInfo={NSLocalizedDescription=failed to open zip file}

EDIT2: I checked with the function fileExists, and file is available

let str = sourceURL

let url = URL(string: str)
print(url!.path,"\n")

if FileManager.default.fileExists(atPath: url!.path) {
    print("FILE IS AVAILABLE")
} else {
    print("FILE NOT AVAILABLE")
}

Thanks in advance

ΩlostA
  • 2,501
  • 5
  • 27
  • 63
  • 2
    Instead of using `unzipFile(atPath:, toDestination:)`, you can use one of the methods that offer error feedback - there are ones with either pointer to error or with completion handler – mag_zbc Mar 14 '19 at 11:10
  • @mag_zbc good answer, I have an error message now... – ΩlostA Mar 14 '19 at 13:32
  • Are you sure you're using correct zip file name? I would assume both file name and extension are case sensitive. – mag_zbc Mar 14 '19 at 14:42
  • @mag_zbc name of the zip file seems good... – ΩlostA Mar 14 '19 at 15:02
  • Did you check that file actually exists? For instance, using `FileManager.default.fileExists(atPath: sourceURL)`? – mag_zbc Mar 14 '19 at 15:04
  • @mag_zbc I just checked with your mentionned function, it says that file exists – ΩlostA Mar 14 '19 at 15:07
  • @mag_zbc my mistake, it is my fault. I renamed it .zip, but it is a .tar.gz file... Thank you for your help – ΩlostA Mar 14 '19 at 15:22

0 Answers0