You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Foundation/NSFileManager.swift
+103-8Lines changed: 103 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -191,20 +191,115 @@ public class NSFileManager : NSObject {
191
191
}
192
192
}
193
193
194
-
/* contentsOfDirectoryAtPath:error: returns an NSArray of NSStrings representing the filenames of the items in the directory. If this method returns 'nil', an NSError will be returned by reference in the 'error' parameter. If the directory contains no items, this method will return the empty array.
194
+
/**
195
+
Performs a shallow search of the specified directory and returns the paths of any contained items.
195
196
196
-
This method replaces directoryContentsAtPath:
197
+
This method performs a shallow search of the directory and therefore does not traverse symbolic links or return the contents of any subdirectories. This method also does not return URLs for the current directory (“.”), parent directory (“..”) but it does return other hidden files (files that begin with a period character).
198
+
199
+
The order of the files in the returned array is undefined.
200
+
201
+
- Parameter path: The path to the directory whose contents you want to enumerate.
202
+
203
+
- Throws: `NSError` if the directory does not exist, this error is thrown with the associated error code.
204
+
205
+
- Returns: An array of String each of which identifies a file, directory, or symbolic link contained in `path`. The order of the files returned is undefined.
// TODO: `entryName` should be limited in length to `entry.memory.d_namlen`.
228
+
if entryName !="." && entryName !=".."{
229
+
contents.append(entryName)
230
+
}
231
+
}
232
+
233
+
entry =readdir(dir)
234
+
}
235
+
236
+
return contents
200
237
}
201
238
202
-
/* subpathsOfDirectoryAtPath:error: returns an NSArray of NSStrings representing the filenames of the items in the specified directory and all its subdirectories recursively. If this method returns 'nil', an NSError will be returned by reference in the 'error' parameter. If the directory contains no items, this method will return the empty array.
203
-
204
-
This method replaces subpathsAtPath:
205
-
*/
239
+
/**
240
+
Performs a deep enumeration of the specified directory and returns the paths of all of the contained subdirectories.
241
+
242
+
This method recurses the specified directory and its subdirectories. The method skips the “.” and “..” directories at each level of the recursion.
243
+
244
+
Because this method recurses the directory’s contents, you might not want to use it in performance-critical code. Instead, consider using the enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: or enumeratorAtPath: method to enumerate the directory contents yourself. Doing so gives you more control over the retrieval of items and more opportunities to abort the enumeration or perform other tasks at the same time.
245
+
246
+
- Parameter path: The path of the directory to list.
247
+
248
+
- Throws: `NSError` if the directory does not exist, this error is thrown with the associated error code.
249
+
250
+
- Returns: An array of NSString objects, each of which contains the path of an item in the directory specified by path. If path is a symbolic link, this method traverses the link. This method returns nil if it cannot retrieve the device of the linked-to file.
/* attributesOfItemAtPath:error: returns an NSDictionary of key/value pairs containing the attributes of the item (file, directory, symlink, etc.) at the path in question. If this method returns 'nil', an NSError will be returned by reference in the 'error' parameter. This method does not traverse a terminal symlink.
0 commit comments