解压无提示 [英] Unzip without prompt
问题描述
我正在创建一个应用程序来解压缩zip文件而不提示.我正在Vmaware中使用MAC OS 10.5映像.
I am creating a application to unzip zip files without prompting. I am using MAC OS 10.5 image in Vmaware.
我是可可编程的新手.我搜索了一些与此相关的代码,但无法正常工作..我没有收到任何错误或警告消息..请告诉我它的正确解决方案. 压缩文件未解压缩,一段时间后我的应用程序关闭.我想在不提示和使用任何第三方存档应用程序的情况下解压缩文件.
I am new in cocoa programing. I searched few codes regarding this, but its not working..I am not getting any error or warning message.. Please kindly tell me its correct solution.. Zip file is not extracting and my application is closing after some time. I want to Unzip file without prompting and using any third party archive application.
我想在其ZIP文件的相同位置解压缩文件.
I want to Unzip my file on the same location of its ZIP file.
这是我的代码:
/* 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];
-谢谢 -问候!
推荐答案
我接受了您的代码并更改了一些选项.您已经指定了所有内容的完整路径.
I took your code and changed some of the options. You have specify the full path to everything.
#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;
}
这篇关于解压无提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!