]> err.no Git - sope/blob - sope-core/samples/testdirenum.m
fixed NGObjWeb for SOPE 3.3
[sope] / sope-core / samples / testdirenum.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #import <Foundation/Foundation.h>
24 #import <EOControl/EOControl.h>
25 #include <NGExtensions/NSFileManager+Extensions.h>
26 #include <NGExtensions/NGFileFolderInfoDataSource.h>
27 #include <NGExtensions/NGDirectoryEnumerator.h>
28
29 @interface TestDirEnumTool : NSObject
30 @end
31
32 @implementation TestDirEnumTool
33
34 - (void)runWithArguments:(NSArray *)args {
35   NSFileManager *fm;
36   NGDirectoryEnumerator *e;
37   NSString      *cpath;
38
39   fm = [NSFileManager defaultManager];
40   
41   e = [[NGDirectoryEnumerator alloc] initWithFileManager:fm
42                                      directoryPath:[args objectAtIndex:1]];
43
44   NSLog(@"enum: %@", e);
45   
46   while ((cpath = [e nextObject])) {
47 #if 1
48     printf("%s\n", [cpath cString]);
49 #else
50     NSDictionary *record;
51
52     record = [e fileAttributes];
53     {
54       /* id uid gid date name */
55       NSString *fileId;
56       NSString *owner;
57       int      gid;
58       unsigned size;
59       NSString *modDate;
60       NSString *fname;
61       NSString *ftype;
62         
63       fileId  = [[record objectForKey:NSFileIdentifier] description];
64       owner   = [record  objectForKey:NSFileOwnerAccountName];
65       gid     = [[record objectForKey:NSFileGroupOwnerAccountNumber] intValue];
66       size    = [[record  objectForKey:NSFileSize] intValue];
67       modDate = [[record objectForKey:NSFileModificationDate] description];
68       fname   = [record  objectForKey:NSFileName];
69       ftype   = [record  objectForKey:NSFileType];
70       
71       if ([ftype isEqualToString:NSFileTypeDirectory])
72         fname = [fname stringByAppendingString:@"/"];
73       else if ([ftype isEqualToString:NSFileTypeSocket])
74         fname = [fname stringByAppendingString:@"="];
75       else if ([ftype isEqualToString:NSFileTypeSymbolicLink])
76         fname = [fname stringByAppendingString:@"@"];
77         
78       //NSLog(@"record: %@", record);
79         
80       printf("%8s  %8s  %8i  %8i  %8s  %s\n",
81              [fileId cString],
82              [owner  cString],
83              gid,
84              size,
85              [modDate cString],
86              [fname cString]);
87     }
88 #endif
89   }
90 }
91
92 @end /* TestDirEnumTool */
93
94 int main(int argc, char **argv, char **env) {
95   NSAutoreleasePool *pool;
96   NSArray *args;
97   id tool;
98   
99   pool = [[NSAutoreleasePool alloc] init];
100 #if LIB_FOUNDATION_LIBRARY
101   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
102 #endif
103   
104   args = [[NSProcessInfo processInfo] arguments];
105   if ([args count] < 1) {
106     NSLog(@"usage: %@ dir", [args objectAtIndex:0]);
107     exit(1);
108   }
109   else if ([args count] == 1)
110     args = [args arrayByAddingObject:@"."];
111   
112   tool = [[TestDirEnumTool alloc] init];
113   [tool runWithArguments:args];
114   
115   exit(0);
116   return 0;
117 }