-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.m
64 lines (47 loc) · 1.57 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#import <Foundation/Foundation.h>
#include <stdio.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSFileManager *filemanager= [[NSFileManager alloc] init];
NSString *filepath;
NSDictionary *attributes;
if(argc!=3)
{
printf("Usage: FileDP [-f/-d] [Full path to file/directory] \n");
return 0;
}
else
{
if(strcmp(argv[1],"-f")==0)
{
filepath=[NSString stringWithCString:argv[2] encoding:NSASCIIStringEncoding];
if([filemanager fileExistsAtPath:filepath]==YES){
attributes=[filemanager attributesOfItemAtPath:filepath error:NULL];
NSLog(@"prot type is %@", [attributes objectForKey:NSFileProtectionKey]);}
else {
printf("File Not Found \n");
}
}
else
{
NSString *dirpath=[NSString stringWithCString:argv[2] encoding:NSASCIIStringEncoding];
if([dirpath hasSuffix:@"/"]==FALSE) {
dirpath=[dirpath stringByAppendingFormat:@"/"];
}
if([filemanager fileExistsAtPath:dirpath]==YES){
NSDirectoryEnumerator *direnum=[filemanager enumeratorAtPath:dirpath];
for(NSString *f in direnum){
filepath=[dirpath stringByAppendingFormat:f];
attributes=[filemanager attributesOfItemAtPath:filepath error:NULL];
NSLog(@"file name is:%@ - protection class:%@", filepath,[attributes objectForKey:NSFileProtectionKey]);
}
}
else {
printf("Directory Not found \n");
}
}
}
[pool drain];
return 0;
}