init(authorization: NSWorkspace.Authorization)
class var `default`: FileManager
class FileManager : NSObject
A file manager object lets you examine the contents of the file system and make changes to it. The File
class provides convenient access to a shared file manager object that is suitable for most types of file-related manipulations. A file manager object is typically your primary mode of interaction with the file system. You use it to locate, create, copy, and move files and directories. You also use it to get information about a file or directory or change some of its attributes.
When specifying the location of files, you can use either NSURL
or NSString
objects. The use of the NSURL
class is generally preferred for specifying file-system items because URLs can convert path information to a more efficient representation internally. You can also obtain a bookmark from an NSURL
object, which is similar to an alias and offers a more sure way of locating the file or directory later.
If you are moving, copying, linking, or removing files or directories, you can use a delegate in conjunction with a file manager object to manage those operations. The delegate’s role is to affirm the operation and to decide whether to proceed when errors occur. In macOS 10.7 and later, the delegate must conform to the File
protocol.
In iOS 5.0 and later and in macOS 10.7 and later, File
includes methods for managing items stored in iCloud. Files and directories tagged for cloud storage are synced to iCloud so that they can be made available to the user’s iOS devices and Macintosh computers. Changes to an item in one location are propagated to all other locations to ensure the items stay in sync.
The methods of the shared File
object can be called from multiple threads safely. However, if you use a delegate to receive notifications about the status of move, copy, remove, and link operations, you should create a unique instance of the file manager object, assign your delegate to that object, and use that file manager to initiate your operations.
init(authorization: NSWorkspace.Authorization)
class var `default`: FileManager
var homeDirectoryForCurrentUser : URL
func NSHomeDirectory () -> String
func NSUserName () -> String
func NSFullUserName () -> String
func homeDirectory (forUser : String) -> URL?
func NSHomeDirectoryForUser (String?) -> String?
var temporaryDirectory : URL
func NSTemporaryDirectory () -> String
func url(for: FileManager.SearchPathDirectory, in: FileManager.SearchPathDomainMask, appropriateFor : URL?, create: Bool) -> URL
func urls(for: FileManager.SearchPathDirectory, in: FileManager.SearchPathDomainMask) -> [URL]
func NSSearchPathForDirectoriesInDomains (FileManager.SearchPathDirectory, FileManager.SearchPathDomainMask, Bool) -> [String]
func NSOpenStepRootDirectory () -> String
func containerURL (forSecurityApplicationGroupIdentifier : String) -> URL?
func contentsOfDirectory (at: URL, includingPropertiesForKeys : [URLResourceKey]?, options: FileManager.DirectoryEnumerationOptions) -> [URL]
func contentsOfDirectory (atPath : String) -> [String]
func enumerator(at: URL, includingPropertiesForKeys : [URLResourceKey]?, options: FileManager.DirectoryEnumerationOptions, errorHandler : ((URL, any Error) -> Bool)?) -> FileManager.DirectoryEnumerator?
func enumerator(atPath : String) -> FileManager.DirectoryEnumerator?
class FileManager.DirectoryEnumerator
func mountedVolumeURLs (includingResourceValuesForKeys : [URLResourceKey]?, options: FileManager.VolumeEnumerationOptions) -> [URL]?
struct FileManager.VolumeEnumerationOptions
mountedVolumeURLs(includingResourceValuesForKeys:options:)
method.func subpathsOfDirectory (atPath : String) -> [String]
func subpaths(atPath : String) -> [String]?
func createDirectory (at: URL, withIntermediateDirectories : Bool, attributes: [FileAttributeKey : Any]?)
func createDirectory (atPath : String, withIntermediateDirectories : Bool, attributes: [FileAttributeKey : Any]?)
func createFile (atPath : String, contents: Data?, attributes: [FileAttributeKey : Any]?) -> Bool
func removeItem (at: URL)
func removeItem (atPath : String)
func trashItem (at: URL, resultingItemURL : AutoreleasingUnsafeMutablePointer<NSURL?>?)
func replaceItemAt (URL, withItemAt : URL, backupItemName : String?, options: FileManager.ItemReplacementOptions) -> URL?
func replaceItem (at: URL, withItemAt : URL, backupItemName : String?, options: FileManager.ItemReplacementOptions, resultingItemURL : AutoreleasingUnsafeMutablePointer<NSURL?>?)
struct FileManager.ItemReplacementOptions
func copyItem (at: URL, to: URL)
func copyItem (atPath : String, toPath : String)
func moveItem (at: URL, to: URL)
func moveItem (atPath : String, toPath : String)
var ubiquityIdentityToken : (any NSCoding & NSCopying & NSObjectProtocol)?
func url(forUbiquityContainerIdentifier : String?) -> URL?
func isUbiquitousItem (at: URL) -> Bool
func setUbiquitous (Bool, itemAt : URL, destinationURL : URL)
func startDownloadingUbiquitousItem (at: URL)
func evictUbiquitousItem (at: URL)
func url(forPublishingUbiquitousItemAt : URL, expiration: AutoreleasingUnsafeMutablePointer<NSDate?>?) -> URL
func getFileProviderServicesForItem (at: URL, completionHandler : ([NSFileProviderServiceName : NSFileProviderService]?, (any Error)?) -> Void)
class NSFileProviderService
struct NSFileProviderServiceName
func createSymbolicLink (at: URL, withDestinationURL : URL)
func createSymbolicLink (atPath : String, withDestinationPath : String)
func linkItem (at: URL, to: URL)
func linkItem (atPath : String, toPath : String)
func destinationOfSymbolicLink (atPath : String) -> String
func fileExists (atPath : String) -> Bool
func fileExists (atPath : String, isDirectory : UnsafeMutablePointer<ObjCBool>?) -> Bool
func isReadableFile (atPath : String) -> Bool
func isWritableFile (atPath : String) -> Bool
func isExecutableFile (atPath : String) -> Bool
func isDeletableFile (atPath : String) -> Bool
func componentsToDisplay (forPath : String) -> [String]?
func displayName (atPath : String) -> String
func attributesOfItem (atPath : String) -> [FileAttributeKey : Any]
func attributesOfFileSystem (forPath : String) -> [FileAttributeKey : Any]
func setAttributes ([FileAttributeKey : Any], ofItemAtPath : String)
func contents(atPath : String) -> Data?
func contentsEqual (atPath : String, andPath : String) -> Bool
func getRelationship (UnsafeMutablePointer<FileManager.URLRelationship>, ofDirectoryAt : URL, toItemAt : URL)
func getRelationship (UnsafeMutablePointer<FileManager.URLRelationship>, of: FileManager.SearchPathDirectory, in: FileManager.SearchPathDomainMask, toItemAt : URL)
enum FileManager.URLRelationship
func fileSystemRepresentation (withPath : String) -> UnsafePointer<CChar>
func string(withFileSystemRepresentation : UnsafePointer<CChar>, length: Int) -> String
NSString
object whose contents are derived from the specified C-string path.var delegate: (any FileManagerDelegate)?
func changeCurrentDirectoryPath (String) -> Bool
var currentDirectoryPath : String
func unmountVolume (at: URL, options: FileManager.UnmountOptions, completionHandler : ((any Error)?) -> Void)
struct FileManager.UnmountOptions
let NSFileManagerUnmountDissentingProcessIdentifierErrorKey : String
func NSFileTypeForHFSTypeCode (OSType) -> String!
func NSHFSTypeCodeFromFileType (String!) -> OSType
func NSHFSTypeOfFile (String!) -> String!
var NSFoundationVersionWithFileManagerResourceForkSupport : Int32
NSFileManager
first supported resource forks.struct FileManager.DirectoryEnumerationOptions
enum FileManager.SearchPathDirectory
struct FileManager.SearchPathDomainMask
struct FileAttributeKey
struct FileAttributeType
struct FileProtectionType
struct URLFileProtection
static let NSUbiquityIdentityDidChange : NSNotification.Name
func changeFileAttributes ([AnyHashable : Any], atPath : String) -> Bool
func fileAttributes (atPath : String, traverseLink : Bool) -> [AnyHashable : Any]?
func fileSystemAttributes (atPath : String) -> [AnyHashable : Any]?
func directoryContents (atPath : String) -> [Any]?
func createDirectory (atPath : String, attributes: [AnyHashable : Any]) -> Bool
func createSymbolicLink (atPath : String, pathContent : String) -> Bool
func pathContentOfSymbolicLink (atPath : String) -> String?
func fileManager (FileManager, shouldProceedAfterError : [AnyHashable : Any]) -> Bool
NSFileManager
object sends this message to its handler for each error it encounters when copying, moving, removing, or linking files or directories. func fileManager (FileManager, willProcessPath : String)
NSFileManager
object sends this message to a handler immediately before attempting to move, copy, rename, or delete, or before attempting to link to a given path.func replaceItemAtURL (originalItemURL : NSURL, withItemAtURL : NSURL, backupItemName : String?, options: FileManager.ItemReplacementOptions) -> NSURL?
protocol FileManagerDelegate