에 의해 바이트 하나를보고, 이것을 시도 것입니다. 대신과 같이 -[NSFileManager moveItemAtPath:toPath:error:]
를 사용
/* Find the user's Desktop directory. */
NSArray *results = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES/*expandTilde*/);
if (![results count]) return;
NSString *parentDir = [results objectAtIndex:0U];
/* Build the source path in a platform-independent manner. */
/* -pathWithComponents: will use the separator ('/', '\', or ':')
* appropriate for the platform. */
NSArray *srcParts = [NSArray arrayWithObjects:@"/", @"Volumes", @"Public", @"Directory*", (void *)nil];
NSString *src = [NSString pathWithComponents:srcParts];
/* Build the destination path. */
NSString *fnam = [src lastPathComponent];
NSString *dest = [parentDir stringByAppendingPathComponent:fnam];
/* Move |src| to |dest|. */
NSFileManager *fm = [NSFileManager defaultManager];
NSError *error = NULL;
BOOL ok = [fm moveItemAtPath:src toPath:dest error:&error];
if (!ok) {
[[NSApplication sharedApplication] presentError:error];
}
당신이, 플랫폼 독립적, 당신은 단지 src
및 dest
인수를 하드 코딩 할 수있는 신경 직접 이동을 수행하고, 75 %가이 단축하지 마십시오.
이 아닌은 "디렉토리 *"라는 디렉토리가있을 것으로 예상됩니다. 여기서 별표는 디렉토리 이름의 마지막 부분입니다. <glob.h>
에 정의 된 glob()
을 사용하여 직접 globbing을 처리 할 수 있습니다.