Reputation: 11
I used this code for deleting files from directory:
[ws performFileOperation: NSWorkspaceRecycleOperation source: @"/Users/user/path" destination: @"" files: [[_l_ArrayController selectedObjects] mutableArrayValueForKey: @"LName"] tag: 0];
[_l_ArrayController removeObjects:[_l_ArrayController selectedObjects]];
and it worked perfect, but if i removed any file from _l_ArrayController, in time via Finder, NSWorkspaceRecycleOperation
don't deleted file's after this.
For example:
I have array of files {one, two, three} and begin delete. If i deleted file "two" via Finder in time, file "three" don't deleted via NSWorkspaceRecycleOperation
.
Upvotes: 1
Views: 530
Reputation: 31
You might be surprised by the behavior of this function if you don't realize that it's taking place asynchronously. The function exits immediately and moves to the next statement in the program, and the recycle operation happens some time later. If the code you've got right after the recycle operation is somehow counting on the notion that the files are gone... you may be in for a surprise. So in this case, you tell NSWorkspace "Here's the array of files to delete." Then in the next step, you pull one of those files out. And then the recycle operation takes place; NSWorkspace says "let's look in that array." It finds some files and performs its operation. It doesn't know that there used to be different files right before it looked. Does that makes sense? There's a couple of things you can do. One, give it a copy of the array, then modify the original. Or put your code in the completionHandler block. That is guaranteed not to execute until the recycle operation is done (successfully or not).
Upvotes: 3