我正在尝试为它编写一个小 RSync 程序,并且我设法让它与下面的代码一起工作。唯一的问题是它只同步单个文件而不是目录。如果您rsync
通过终端命令运行,它可以将整个目录复制到其他目录中。有人知道修复吗?
NSString *source = self.source.stringValue;
NSString *destination = self.destination.stringValue;
NSLog(@"The source is %@. The destination is %@.", source, destination);
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/rsync"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: source, destination, nil];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
我有两个用于源和目标的文本字段,我采用字符串值并将它们设置为等于源和目标。