Changeset 166


Ignore:
Timestamp:
Mar 28, 2006, 6:26:13 AM (16 years ago)
Author:
titer
Message:

Finder-independent trashPath: method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Torrent.m

    r165 r166  
    371371- (void) trashPath: (NSString *) path
    372372{
    373     NSString * string;
    374     NSAppleScript * appleScript;
    375     NSDictionary * error;
    376 
    377     string = [NSString stringWithFormat:
    378         @"tell application \"Finder\"\n"
    379          "  move (POSIX file \"%@\") to trash\n"
    380          "end tell", path];
    381    
    382     appleScript = [[NSAppleScript alloc] initWithSource: string];
    383     if( ![appleScript executeAndReturnError: &error] )
    384     {
    385         printf( "trashPath failed\n" );
    386     }
    387     [appleScript release];
     373    if( ![[NSWorkspace sharedWorkspace] performFileOperation:
     374           NSWorkspaceRecycleOperation source:
     375           [path stringByDeletingLastPathComponent]
     376           destination: @""
     377           files: [NSArray arrayWithObject: [path lastPathComponent]]
     378           tag: nil] )
     379    {
     380        /* We can't move it to the trash, let's try just to delete it
     381           (will work if it is on a remote volume) */
     382        if( ![[NSFileManager defaultManager]
     383                removeFileAtPath: path handler: nil] )
     384        {
     385            printf( "Could not trash `%s'\n", [path UTF8String] );
     386        }
     387    }
    388388}
    389389
Note: See TracChangeset for help on using the changeset viewer.