解压没有提示
我正在创建一个应用程序来解压缩 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];
-谢谢 -问候!
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.
I want to Unzip my file on the same location of its ZIP file.
Here is my code:
/* 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];
-Thanks
-with regards !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我拿了你的代码并更改了一些选项。您已指定所有内容的完整路径。
I took your code and changed some of the options. You have specify the full path to everything.
不确定这是否是您唯一的问题,但您需要扩展路径中的波浪号 (
~
)。通常这是由 shell 完成的,但如果您不使用 shell,则必须自己完成。幸运的是,有一个NSString
方法可以做到这一点,因此您可以执行[@"~/Desktop/demos.zip" stringByExpandingTildeInPath]
和[@"~ /Desktop" stringByExpandingTildeInPath]
。Not sure if this is your only issue, but you need to expand the tildes (
~
) in your path. Normally this is done by the shell, but if you're not using the shell, you have to do it yourself. Luckily, there's anNSString
method for doing just that, so you can do[@"~/Desktop/demos.zip" stringByExpandingTildeInPath]
and[@"~/Desktop" stringByExpandingTildeInPath]
.