처음에 휴지통 폴더에있는 항목을 다운로드에서 삭제하려고 시도하고 있습니다. 아래 구현에서 누락 된 부분은 파일이 이동되지 않습니다.휴지통으로 항목을 옮길 수 없습니다
구체적인 : BergQuester에 의해 제안 나는 아래의 코드로 시도
NSString *trashpath=[NSHomeDirectory() stringByAppendingPathComponent:@".Trash"];
NSString *downloadpath=[NSHomeDirectory() stringByAppendingPathComponent:@"Downloads"];
- (void) moveToTrash{
NSError * error = nil;
NSArray * list = [_filemanager contentsOfDirectoryAtPath:_downloadpath error:&error];
//Move items to the trash
for(id obj in list){
NSString *sourcepath = [_downloadpath stringByAppendingPathComponent:obj];
NSString *destpath= [_trashpath stringByAppendingPathComponent:obj];
if([_filemanager moveItemAtPath:sourcepath toPath:destpath error:&error] == YES)
NSLog(@"Moved to trash :%@ ",destpath);
else
NSLog(@"Unable to move %@ ",sourcepath);
}
}
는
if([[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:_downloadpath
destination:@"" files:list tag:nil] == YES)
NSLog(@"Moved to Trash");
else
NSLog(@"Unable to move :%@",[error localizedFailureReason]);
나는 MOV 할 수 없음 얻을 전자 : (null) 내 출력.
파일이 실제로 있으므로 문제가 아직 무엇인지 확실하지 않습니다.
왜 [trashItemAtURL : resultingItemURL : 오류] 할 (https://developer.apple.com/library/ mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html # // apple_ref/occ/instm/NSFileManager/trashItemAtURL : resultsItemURL : 오류 :)? –
@ JohnSauer이 부분을 살펴 보겠습니다. – Fabii
@JohnSauer, 각 파일을 반복하고 아래에있는 bergquester에서 제안한대로 개별적으로 이동하지 않는 것이 좋습니다. – Fabii