解压没有提示

发布于 2024-10-28 08:11:43 字数 907 浏览 0 评论 0原文

我正在创建一个应用程序来解压缩 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耀眼的星火 2024-11-04 08:11:43

我拿了你的代码并更改了一些选项。您已指定所有内容的完整路径。

#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;
}

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;
}
心不设防 2024-11-04 08:11:43

不确定这是否是您唯一的问题,但您需要扩展路径中的波浪号 (~)。通常这是由 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 an NSString method for doing just that, so you can do [@"~/Desktop/demos.zip" stringByExpandingTildeInPath] and [@"~/Desktop" stringByExpandingTildeInPath].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文