Created
January 28, 2013 10:40
-
-
Save pajp/4654527 to your computer and use it in GitHub Desktop.
simple OS X command-line utility to trash files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <CoreServices/CoreServices.h> | |
/* | |
* compile with: | |
* cc -o simpletrasher -framework CoreServices simpletrasher.c | |
*/ | |
int main(int argc, const char** argv) { | |
for (int i=1; i < argc; i++) { | |
char *trash_path = NULL; | |
const char *file_to_trash = argv[i]; | |
OSStatus err = FSPathMoveObjectToTrashSync(file_to_trash, &trash_path, kFSFileOperationDefaultOptions); | |
if (err != noErr) { | |
fprintf(stderr, "Failed to trash %s.\n", file_to_trash); | |
return 1; | |
} | |
fprintf(stdout, "Trashed %s to %s\n", file_to_trash, trash_path); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment