RSYNC directories versus files

I'm trying to build a little RSync program, damn it, and I managed to get it to work with the code below. The only problem is that these are only rsyncs, not directories. If you run rsync through a terminal command, it can copy entire directories to other directories. Does anyone know a fix?

  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]; 

I have two text fields for the source and destination, for which I take a string value and set those that are equal to the source and destination.

+1
source share
1 answer

If you called rsync on the command line, there is a switch that you would use to get the effect you are describing: the -a option: this is an abbreviation for several other options, the most relevant of which is the instruction for rsync to recurs from the source directory.

This will recursively copy the directory "foo" and all its contents to the "bar" directory. If "bar" does not exist, rsync will create it and then copy "foo" into it.

 rsync -a foo bar 

... will result in bar / foo / everything

Another petty (but important!) Detail to be aware of is whether to put the trailing slash in the source directory. If you said:

 rsync -a foo/ bar 

... you would end with / bar / everything, but on the receiving side there was no directory named "foo".

You would say: "Copy the contents to the foo directory to the directory line ... but not to the directory-directory, foo."

Sorry, this is no more objective-C, but hopefully this will help you with rsync.

+3
source

All Articles