我正在尝试订阅移动到垃圾 MacOS 事件并将文件夹复制回来。代码适用于默认英文字母,但是当我使用乌尔都语和乌尔都语数字格式时, copyItemAtPath在复制时找不到文件夹。
打回来:
void fsevents_callback(ConstFSEventStreamRef streamRef,
void * userData,
size_t numEvents,
void * eventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[]) {
FSEventsListener * eventListener = (__bridge FSEventsListener * ) userData;
char ** paths = eventPaths;
for (int i = 0; i < numEvents; i++) {
NSString * name = [NSString stringWithFormat: @ "%s", paths[i]];
NSLog(@ "Path: %@ (flag = %d)", name, eventFlags[i]);
if (eventFlags[i] & kFSEventStreamEventFlagItemRenamed) {
[eventListener.delegate fileWasRenamed: name];
} else {
[eventListener.delegate fileWasTouched: name];
}
}
}
听众:
- (void)fileWasRenamed:(NSString *)aPath
{
NSString *trashPath = [NSSearchPathForDirectoriesInDomains(NSTrashDirectory, NSUserDomainMask, YES) lastObject];
if (nil != aPath && NSNotFound != [aPath rangeOfString:trashPath].location)
{
NSString *trashFilePath = aPath;
if (nil != self.removedFilePath && NSNotFound != [trashFilePath.lastPathComponent rangeOfString:self.removedFilePath.lastPathComponent.stringByDeletingPathExtension].location)
{
NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isCopied = [fileManager copyItemAtPath:trashFilePath toPath:self.removedFilePath error:&error];
}
}
}
当我尝试复制时,我得到了错误:
错误域 = NSPOSIXErrorDomain 代码 = 2“没有这样的文件或目录”
垃圾箱中的文件名:我的文件夹 17.57.44