-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUCFileList.m
More file actions
105 lines (85 loc) · 1.95 KB
/
Copy pathUCFileList.m
File metadata and controls
105 lines (85 loc) · 1.95 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// UCFileList.m
// Chain
//
// Created by Christoph on 12.06.2009.
// Copyright 2009 Useless Coding. All rights reserved.
//
#import "UCFileList.h"
@implementation UCFileList
- (id)initForPath:(NSString *)aPath withTypes:(NSArray *)theTypes
{
if(self=[self init])
{
BOOL isFolder;
if(![[NSFileManager defaultManager] fileExistsAtPath:aPath isDirectory:&isFolder])
{
[self release];
return nil;
}
if(isFolder)
{
folder = [aPath copy];
}
else
{
folder = [[aPath stringByDeletingLastPathComponent] retain];
}
filterTypes = [theTypes retain];
NSWorkspace * ws = [NSWorkspace sharedWorkspace];
NSArray * allFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:folder error:NULL];
NSUInteger i,j;
NSUInteger typeCount=[filterTypes count];
NSUInteger fileCount=[allFiles count];
files = [[NSMutableArray alloc] initWithCapacity:fileCount];
currentIndex = NSNotFound;
NSString *file, *fileType, *testType, *fullFile;
for(i=0; i<fileCount; i++)
{
file = (NSString *)[allFiles objectAtIndex:i];
fullFile = [folder stringByAppendingPathComponent:file];
fileType = [ws typeOfFile:fullFile error:NULL];
for(j=0; j<typeCount; j++)
{
testType = (NSString *)[filterTypes objectAtIndex:j];
if([ws type:fileType conformsToType:testType])
{
[files addObject:file];
if([fullFile isEqualToString:aPath])
{
currentIndex = [files count]-1;
}
break;
}
}
}
if(isFolder && [files count])
{
currentIndex = 0;
}
}
return self;
}
- (void) dealloc
{
[files release];
[folder release];
[filterTypes release];
[super dealloc];
}
#pragma mark -
- (NSString *)currentFile
{
if(currentIndex==NSNotFound)
{
return nil;
}
return [folder stringByAppendingPathComponent:[files objectAtIndex:currentIndex]];
}
- (NSUInteger)count
{
return [files count];
}
@synthesize folder=folder;
@synthesize currentIndex=currentIndex;
@end