Created
October 28, 2008 09:03
-
-
Save mrkn/20330 to your computer and use it in GitHub Desktop.
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
/* gcc -framework Foundation -framework AppKit -o file_wo_kesu file_wo_kesu.m */ | |
#import <Foundation/NSArray.h> | |
#import <Foundation/NSAutoreleasePool.h> | |
#import <Foundation/NSDictionary.h> | |
#import <Foundation/NSFileManager.h> | |
#import <Foundation/NSProcessInfo.h> | |
#import <Foundation/NSString.h> | |
#import <AppKit/NSOpenPanel.h> | |
#import <stdio.h> | |
#import <stdlib.h> | |
int | |
main(int argc, char** argv) | |
{ | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
NSOpenPanel* openPanel = [NSOpenPanel openPanel]; | |
[openPanel setCanChooseDirectories: YES]; | |
int result = [openPanel runModalForDirectory: NSHomeDirectory() file: nil types: nil]; | |
if (result == NSOKButton) { | |
NSString* dirpath = [openPanel filename]; | |
printf("location: %s OK? [Y/n]: ", [dirpath UTF8String]); | |
fflush(stdout); | |
char yesno[3]; | |
fgets(yesno, 3, stdin); | |
if (yesno[0] != 'Y' && yesno[0] != 'y') { | |
printf("operation canceled.\n"); | |
exit(EXIT_SUCCESS); | |
} | |
NSFileManager* nsfm = [NSFileManager defaultManager]; | |
NSDirectoryEnumerator* direnum = [nsfm enumeratorAtPath: dirpath]; | |
if (chdir([dirpath UTF8String]) < 0) { | |
perror("chdir"); | |
exit(EXIT_FAILURE); | |
} | |
NSString *pname = nil; | |
while ((pname = [direnum nextObject]) != nil) { | |
NSString* path = [dirpath stringByAppendingPathComponent: pname]; | |
NSDictionary* attr = [direnum fileAttributes]; | |
NSNumber* inode = [attr objectForKey: NSFileSystemFileNumber]; | |
printf("%d %s\n", [inode intValue], [path UTF8String]); | |
[nsfm removeFileAtPath: path handler: nil]; | |
} | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment