aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMNSFileManager+Path.h
blob: 80977b3d329118756bb762b40bde979fe35333b6 (plain)
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
//
//  GTMNSFileManager+Path.h
//
//  Copyright 2006-2008 Google Inc.
//
//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
//  use this file except in compliance with the License.  You may obtain a copy
//  of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
//  License for the specific language governing permissions and limitations under
//  the License.
//

#import <Foundation/Foundation.h>


/// A few useful methods for dealing with paths.
@interface NSFileManager (GMFileManagerPathAdditions)

#if GTM_MACOS_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)

/// For the Unix-y at heart, this is "mkdir -p".  It tries to create
/// the directory specified by |path|, and any intervening directories that
/// are needed.  Each directory that is created is created with |attributes|
/// (see other NSFileManager doco for the details on |attributes|).
///
/// If you are building for 10.5 or later, you should just use the new api:
///  createDirectoryAtPath:withIntermediateDirectories:attributes:error:
///
/// Also if you need more control over the creation of paths and their
/// attributes, look into using GTMPath.
///
/// Args:
///   path - the path of the directory to create.
///   attributes - these are defined in the "Constants" section of Apple's
///                NSFileManager doco
///
/// Returns:
///   YES if |path| exists or was able to be created successfully
///   NO otherwise
///
- (BOOL)gtm_createFullPathToDirectory:(NSString *)path
                           attributes:(NSDictionary *)attributes;

#endif  // GTM_MACOS_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)

/// Return an the paths for all resources in |directoryPath| that have the
/// |extension| file extension.
///
/// Args:
///   extension - the file extension (excluding the leading ".") to match.
///               If nil, all files are matched.
///   directoryPath - the directory to look in.  NOTE: Subdirectories are NOT
///                   traversed.
///
/// Returns:
///   An NSArray of absolute file paths that have |extension|.  nil is returned
///   if |directoryPath| doesn't exist or can't be opened, and returns an empty
///   array if |directoryPath| is empty.  ".", "..", and resource forks are never returned.
///
- (NSArray *)gtm_filePathsWithExtension:(NSString *)extension
                            inDirectory:(NSString *)directoryPath;

/// Same as -filePathsWithExtension:inDirectory: except |extensions| is an
/// NSArray of extensions to match.
///
- (NSArray *)gtm_filePathsWithExtensions:(NSArray *)extensions
                             inDirectory:(NSString *)directoryPath;

@end