t3r*_*t0r 3 macos xcode objective-c
我正在创建一个应用程序来解压缩zip文件而不提示.我在Vmaware中使用MAC OS 10.5映像.
我是可可编程的新手.我搜索了几个关于此的代码,但它没有工作..我没有收到任何错误或警告消息..请告诉我它的正确解决方案..Zip文件没有解压缩,我的应用程序在一段时间后关闭.我想在不提示和使用任何第三方存档应用程序的情况下解压缩文件.
我想在ZIP文件的同一位置解压缩我的文件.
这是我的代码:
/* Assumes sourcePath and targetPath are both
valid, standardized paths. */
// Create the zip task
NSTask * backupTask = [[NSTask alloc] init];
[backupTask setLaunchPath:@"/usr/bin/ditto"];
[backupTask setArguments:
[NSArray arrayWithObjects:@"-c", @"-k", @"-X", @"--rsrc",
@"~/Desktop/demos.zip", @"~/Desktop", nil]];
// Launch it and wait for execution
[backupTask launch];
[backupTask waitUntilExit];
// Handle the task's termination status
if ([backupTask terminationStatus] != 0)
NSLog(@"Sorry, didn't work.");
// You *did* remember to wash behind your ears ...
// ... right?
[backupTask release];
Run Code Online (Sandbox Code Playgroud)
- 谢谢 - 问候!
我拿了你的代码并改变了一些选项.您已指定所有内容的完整路径.
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Need to use the full path to everything
// In this example, I am using my Downloads directory
NSString *destination = [@"~/Downloads" stringByExpandingTildeInPath];
NSString *zipFile = [@"~/Downloads/demos.zip" stringByExpandingTildeInPath];
NSTask *unzip = [[NSTask alloc] init];
[unzip setLaunchPath:@"/usr/bin/unzip"];
[unzip setArguments:[NSArray arrayWithObjects:@"-u", @"-d",
destination, zipFile, nil]];
NSPipe *aPipe = [[NSPipe alloc] init];
[unzip setStandardOutput:aPipe];
[unzip launch];
[unzip waitUntilExit];
[unzip release];
// You can get rid of all the NSLog once you have finish testing
NSData *outputData = [[aPipe fileHandleForReading] readDataToEndOfFile];
NSString *outputString = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
NSLog(@"Zip File: %@", zipFile);
NSLog(@"Destination: %@", destination);
NSLog(@"Pipe: %@", outputString);
NSLog(@"------------- Finish -----------");
[outputString release];
[pool release];
return 0;
}
Run Code Online (Sandbox Code Playgroud)