English 中文(简体)
RSYNC 目录与文件
原标题:RSYNC Directories vs Files

我试图为它设计一个小的 RSync 程序, 我设法把它用下面的代码工作。 唯一的问题是它只使用 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];

我有两个文本字段, 用于源代码和目的地, 我选择字符串值, 并设定与源代码和目的地相等的文本字段 。

最佳回答

如果您在命令线上调用 rsync, 您将会使用一个开关来获取您重新描述的效果 : “ - a” 选项: 它是其他几个选项的简称, 最相关的选项是 rsync 从源目录中递归的指令 。

这将自动将目录“ foo” 及其全部内容复制到目录“ bar” 。 如果“ bar” 不存在, rsync 将会创建它, 然后将“ foo” 复制到目录中 。

rsync -a foo bar

......会导致吐槽/粪便/一切

需要注意的另外一个小细节(但很重要! ) 是您是否在源目录上设置了尾部斜线 。 如果您相反地说 :

rsync -a foo/ bar

...你最终与/bar/ everything, 但是没有目录 被称为"foo"在接收方。

你的意思是“把目录 foo 的 < strong > contents 复制到目录栏... 而不是随附目录 foo 。”

对不起,这不是更客观的C具体, 但希望这能让你与rsync一起走。

问题回答

暂无回答




相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...