NSFileManage

NSFileManager

/** 返回一个NSFileManager实例 */
@property (class, readonly, strong) NSFileManager *defaultManager;

mountedVolumeURLsIncludingResourceValuesForKeys:options:

/**
 注意:此方法在macOS以外的平台上返回nil。
 返回一组URL,用于标识设备上可用的已装入卷。
 @param propertyKeys 一组键,用于标识要为每个卷预取的文件属性。对于每个返回的URL,这些键的值都缓存在相应的NSURL对象中。您可以nil为此参数指定。
 @param options	 	 NSVolumeEnumerationOptions
 @return 一组NSURL对象,用于标识已安装的卷。
 */
- (nullable NSArray<NSURL *> *)mountedVolumeURLsIncludingResourceValuesForKeys:(nullable NSArray<NSURLResourceKey> *)propertyKeys 
																	   options:(NSVolumeEnumerationOptions)options;

unmountVolumeAtURL:options:completionHandler:

/**
 注意:此方法为macOS方法
 启动卸载指定卷的过程
 @param url 指定要卸载的卷的文件URL
 @param mask 可用于自定义卸载操作行为的位掩码。NSFileManagerUnmountOptions
 @param completionHandler 卸载操作完成时执行的块。该块接收NSError参数,nil如果卸载成功则该参数。否则,它表示卸载失败的原因。
 */
- (void)unmountVolumeAtURL:(NSURL *)url
                   options:(NSFileManagerUnmountOptions)mask
         completionHandler:(void (^)(NSError * _Nullable errorOrNil))completionHandler;

contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error:

/**
 搜索指定目录中的第一级内容(文件、目录)
 @param url   要搜索的目录的URL
 @param keys  用来指定获取搜索到的文件/目录的文件属性
 		      对于每个返回的URL,将在NSURL对象中提取和缓存指定的属性,如果不需要,该参数传nil。
 @param mask  因为此方法仅执行浅枚举,唯一支持的选项:NSDirectoryEnumerationSkipsHiddenFiles
 @param error 错误信息
 @return 一组NSURL对象,每个对象标识包含在其中的文件,目录或符号链接url。如果目录不包含任何条目,则此方法返回空数组。如果发生错误,此方法将返回nil并为error参数指定适当的错误对象
 */
- (nullable NSArray<NSURL *> *)contentsOfDirectoryAtURL:(NSURL *)url 
							 includingPropertiesForKeys:(nullable NSArray<NSURLResourceKey> *)keys 
												options:(NSDirectoryEnumerationOptions)mask 
												  error:(NSError **)error;												  

URLsForDirectory:inDomains:

/**
返回指定公共目录的URL数组。
 @param directory  搜索路径目录
 @param domainMask 要搜索的文件系统域。此参数的值是一个或多个描述的常量。
 @return NSURL标识所请求目录的对象数组。根据域掩码常量的顺序对目录进行排序,首先是用户域中的项目,最后是系统域中的项目。
 */
- (NSArray<NSURL *> *)URLsForDirectory:(NSSearchPathDirectory)directory
                             inDomains:(NSSearchPathDomainMask)domainMask;

URLForDirectory:inDomain:appropriateForURL:create:error:

/**
 定位并可选地创建指定的公共目录
 @param directory 搜索路径目录
 @param domain 要搜索的文件系统域。此参数的值是一个或多个描述的常量
 @param url 用于确定返回的URL位置的文件URL。除非directory参数包含值NSItemReplacementDirectory且domain参数包含值NSUserDomainMask,否则将忽略此参数。
 @param shouldCreate 是否创建目录(如果该目录尚不存在)。创建临时目录时,将忽略此参数,并始终创建目录。
 @param error 错误信息
 @return 公共目录的URL
 */
- (nullable NSURL *)URLForDirectory:(NSSearchPathDirectory)directory
                           inDomain:(NSSearchPathDomainMask)domain
                  appropriateForURL:(nullable NSURL *)url
                             create:(BOOL)shouldCreate
                              error:(NSError **)error;

getRelationship:ofDirectoryAtURL: toItemAtURL:error:

/**
 确定目录和项之间存在的关系类型
 @param outRelationship 指向一个变量的指针,用于放置directoryURL和otherURL之间的关系
 @param directoryURL 可能包含otherURL中项目的目录的URL
 @param otherURL 正在测试与directoryURL的关系的文件或目录的URL
 @param error 错误信息
 @return 如果成功确定了项之间的关系,则为true;如果发生错误,则为false。
 */
- (BOOL)getRelationship:(NSURLRelationship *)outRelationship
       ofDirectoryAtURL:(NSURL *)directoryURL
            toItemAtURL:(NSURL *)otherURL
                  error:(NSError **)error;

getRelationship:ofDirectory: inDomain: toItemAtURL:error:

/**
 确定目录和项之间存在的关系类型
 @param outRelationship 指向一个变量的指针,用于放置directoryURL和otherURL之间的关系
 @param directory 搜索路径目录
 @param domainMask 要搜索的文件系统域
 @param url 正在测试与directoryURL的关系的文件或目录的URL
 @param error 错误信息
 @return 如果成功确定了项之间的关系,则为true;如果发生错误,则为false。
 */
- (BOOL)getRelationship:(NSURLRelationship *)outRelationship
            ofDirectory:(NSSearchPathDirectory)directory
               inDomain:(NSSearchPathDomainMask)domainMask
            toItemAtURL:(NSURL *)url
                  error:(NSError **)error;

createDirectoryAtURL:withIntermediateDirectories:attributes:error:

/**
 在指定的URL处创建具有给定属性的目录。
 @param url   				要创建的目录的URL(格式必须为file:///开头)
 							如果要指定相对路径,则必须在创建相应的NSURL对象之前设置当前工作目录。此参数不得为nil
 @param createIntermediates 如果YES,则此方法创建任何不存在的父目录,作为在url中创建目录的一部分。
 							如果为NO,则如果任何中间父目录不存在,则此方法将失败。
 @param attributes 			新目录的文件属性
 @param error 错误信息
 @return 创建结果
 */
- (BOOL)createDirectoryAtURL:(NSURL *)url
 withIntermediateDirectories:(BOOL)createIntermediates
                  attributes:(nullable NSDictionary<NSFileAttributeKey, id> *)attributes
                       error:(NSError **)error;

createSymbolicLinkAtURL:withDestinationURL:error:

/**
 创建文件/目录的快捷方式
 @param url 	目标地址(格式必须为file:///开头)
 @param destURL 源地址(格式必须为file:///开头)
 @param error 错误信息
 @return 创建结果
 */
- (BOOL)createSymbolicLinkAtURL:(NSURL *)url
             withDestinationURL:(NSURL *)destURL
                          error:(NSError **)error;

setAttributes:ofItemAtPath:error:

/**
 设置指定文件或目录的属性
 @param attributes 文件或目录属性
 @param path 文件或目录的路径
 @param error 错误信息
 @return 设置结果
 */
- (BOOL)setAttributes:(NSDictionary<NSFileAttributeKey, id> *)attributes
         ofItemAtPath:(NSString *)path
                error:(NSError **)error;

createDirectoryAtPath:withIntermediateDirectories:attributes:error:

/**
 在指定路径创建具有给定属性的目录
 @param path 				要创建的目录的路径字符串
 @param createIntermediates 如果YES,则此方法创建任何不存在的父目录,作为在路径中创建目录的一部分。 
 							如果为NO,则如果任何中间父目录不存在,则此方法将失败。 如果任何中间路径元素对应于文件而不是目录,则此方法也会失败。
 @param attributes 			新建目录和它新建的父目录的文件属性
 @param error 错误信息
 @return 创建结果
 */
- (BOOL)createDirectoryAtPath:(NSString *)path
  withIntermediateDirectories:(BOOL)createIntermediates
                   attributes:(nullable NSDictionary<NSFileAttributeKey, id> *)attributes
                        error:(NSError **)error;

contentsOfDirectoryAtPath:error:

/**
 对指定的目录进行遍历,返回它所包含的文件和目录(不会获取子二级目录的内容)
 @param path  要遍历其内容的目录的地址
 @param error 错误信息
 @return 目录下的内容
 */
- (nullable NSArray<NSString *> *)contentsOfDirectoryAtPath:(NSString *)path
                                                      error:(NSError **)error;

subpathsOfDirectoryAtPath:error:

/**
 对指定的目录进行遍历,返回它所包含的文件和目录(子目录的内容也会获取)
 @param path  要遍历其内容的目录的地址
 @param error 错误信息
 @return 目录下的内容
 */
- (nullable NSArray<NSString *> *)subpathsOfDirectoryAtPath:(NSString *)path
                                                      error:(NSError **)error;

attributesOfItemAtPath:error:

/**
 返回指定路径下的文件/目录的文件属性
 @param path  路径 
 @param error 错误信息
 @return 内容属性
 */
- (nullable NSDictionary<NSFileAttributeKey, id> *)attributesOfItemAtPath:(NSString *)path 
																	error:(NSError **)error;

attributesOfFileSystemForPath:error:

/**
 返回一个字典,该字典描述给定路径所在的已装入文件系统的属性。
 @param path 装入的文件系统中的任何路径名。
 @param error 错误信息
 @return 文件系统属性
 */
- (nullable NSDictionary<NSFileAttributeKey, id> *)attributesOfFileSystemForPath:(NSString *)path
                            											   error:(NSError **)error;

createSymbolicLinkAtPath:withDestinationPath:error:

/**
 给文件/文件夹创建一个快捷方式
 @param path 	 目标地址
 @param destPath 源地址
 @param error 	 错误信息
 @return 创建结果
 */
- (BOOL)createSymbolicLinkAtPath:(NSString *)path
             withDestinationPath:(NSString *)destPath
                           error:(NSError **)error;

destinationOfSymbolicLinkAtPath:error:

/**
 获取文件/文件夹快捷方式的原身
 @param path  快捷方式路径
 @param error 错误信息
 @return 路径
 */
- (nullable NSString *)destinationOfSymbolicLinkAtPath:(NSString *)path
                                                 error:(NSError **)error;

copyItemAtPath:toPath:error:

/**
 将指定路径下的文件/目录复制到目标路径下
 @param srcPath 源路径
 @param dstPath 目标路径
 @param error 	错误信息
 @return 复制结果
 */
- (BOOL)copyItemAtPath:(NSString *)srcPath
                toPath:(NSString *)dstPath
                 error:(NSError **)error;

moveItemAtPath:toPath:error:

/**
 将指定路径下的文件/目录同步移动到新位置(如果有同名文件会操作失败)
 @param srcPath 源路径
 @param dstPath 目标路径
 @param error 	错误信息
 @return 操作结果
 */
- (BOOL)moveItemAtPath:(NSString *)srcPath
                toPath:(NSString *)dstPath
                 error:(NSError **)error;

linkItemAtPath:toPath:error:

/**
 给一个文件/目录创建硬连接
 @param srcPath 源地址
 @param dstPath 目标地址
 @param error 	错误信息
 @return 操作结果
 */
- (BOOL)linkItemAtPath:(NSString *)srcPath
                toPath:(NSString *)dstPath
                 error:(NSError **)error;

removeItemAtPath:error:

/**
 删除指定路径上的文件或目录
 @param path  要删除的文件/目录地址,如果是目录,则递归删除该目录的内容。您可以nil为此参数指定。
 @param error 错误信息
 @return 操作结果
 */
- (BOOL)removeItemAtPath:(NSString *)path
                   error:(NSError **)error;

copyItemAtURL:toURL:error:

/**
 将指定URL处的文件同步复制到新位置
 @param srcURL 源URL(格式必须为file:///开头)
 @param dstURL 目标URL(格式必须为file:///开头)
 @return 操作结果
 */
- (BOOL)copyItemAtURL:(NSURL *)srcURL
                toURL:(NSURL *)dstURL
                error:(NSError *)error;

moveItemAtURL:toURL:error:

/**
 将指定文件/目录移动到新的地址下
 @param srcURL 源URL(格式必须为file:///开头)
 @param dstURL 目标URL(格式必须为file:///开头)
 @param error  错误信息
 @return 操作结果
 */
- (BOOL)moveItemAtURL:(NSURL *)srcURL
                toURL:(NSURL *)dstURL
                error:(NSError **)error;

linkItemAtURL:toURL:error:

/**
 创建URL硬连接
 @param srcURL 源URL(格式必须为file:///开头)
 @param dstURL 目标URL(格式必须为file:///开头)
 @param error  错误信息
 @return 操作结果
 */
- (BOOL)linkItemAtURL:(NSURL *)srcURL
                toURL:(NSURL *)dstURL
                error:(NSError **)error;

removeItemAtURL:error:

/**
 删除指定的文件/目录
 @param URL   目标URL(格式必须为file:///开头)
 @param error 错误信息
 @return 操作结果
 */
- (BOOL)removeItemAtURL:(NSURL *)URL
                  error:(NSError **)error;

trashItemAtURL:resultingItemURL:error:

/**
 将项目移动到废纸篓
 @param url 要移动到废纸篓的项目地址
 @param outResultingURL 项目移动到废纸篓后的URL地址
 @param error 错误信息
 @return 操作结果
 */
- (BOOL)trashItemAtURL:(NSURL *)url
      resultingItemURL:(NSURL * _Nullable * _Nullable)outResultingURL
                 error:(NSError **)error;

currentDirectoryPat

/** 当前目录地址 */
@property (readonly, copy) NSString *currentDirectoryPath;

changeCurrentDirectoryPath:

/**
 设置当前目录路径
 @param path 指定目录路径
 @return 操作结果
 */
- (BOOL)changeCurrentDirectoryPath:(NSString *)path;

fileExistsAtPath:isDirectory:

/**
 返回一个BOOL,表示文件或目录是否存在于指定路径中
 @param path 		文件/目录的路径。如果path以波浪号(~)开头,则必须首先展开; 否则,此方法返回NO。
 @param isDirectory 返回时,如果path是目录或者最终路径元素是指向目录的符号链接,则返回YES; 否则NO。 
 					如果path不存在,则返回时该值未定义。 如果您不需要此信息,请传递NULL。
 @return 判断结果
 */
- (BOOL)fileExistsAtPath:(NSString *)path;
- (BOOL)fileExistsAtPath:(NSString *)path
             isDirectory:(nullable BOOL *)isDirectory;

isReadableFileAtPath:

/**
 判断文件/目录是否可读
 @param path 目标路径
 @return 判断结果
 */
- (BOOL)isReadableFileAtPath:(NSString *)path;

isWritableFileAtPath:

/**
 判断文件/目录是否可写
 @param path 目标路径
 @return 判断结果
 */
- (BOOL)isWritableFileAtPath:(NSString *)path;

isExecutableFileAtPath:

/**
 判断文件/目录是否可执行
 @param path 目标路径
 @return 判断结果
 */
- (BOOL)isExecutableFileAtPath:(NSString *)path;

isDeletableFileAtPath:

/**
 判断文件/目录是否可删除
 @param path 目标路径
 @return 判断结果
 */
- (BOOL)isDeletableFileAtPath:(NSString *)path;

contentsEqualAtPath:andPath:

/**
 比较两个文件/目录的内容是否相同
 @param path1 要与path2比较的文件/目录
 @param path2 要与path1比较的文件/目录
 @return 比较结果
 */
- (BOOL)contentsEqualAtPath:(NSString *)path1 
  					andPath:(NSString *)path2;

displayNameAtPath:

/**
 返回指定文件/目录显示的名称
 @param path 目标路径
 @return 显示名称
 */
- (NSString *)displayNameAtPath:(NSString *)path;

componentsToDisplayForPath:

/**
 获取目标地址的每一级父地址
 @param path 目标地址
 @return 存放每一级父地址的数组
 */
- (nullable NSArray<NSString *> *)componentsToDisplayForPath:(NSString *)path;

enumeratorAtPath:

/**
 返回一个目录枚举器对象,该对象可用于在指定路径上执行目录的深枚举
 @param path 目标路径
 @return 枚举对象
 */
- (nullable NSDirectoryEnumerator<NSString *> *)enumeratorAtPath:(NSString *)path;

enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:

/**
 返回一个目录枚举器对象,该对象可用于在指定的URL处执行目录的深枚举
 @param url 	要枚举的目录的位置
 @param keys 	一组键,用于标识要为枚举中的每个项预取的属性。
 @param mask 	枚举的选项。 有关有效选项的列表,请参阅NSDirectoryEnumerationOptions
 @param handler 一个可选的错误处理程序块,供文件管理器在发生错误时调用。
                如果希望枚举继续,则处理程序块应返回YES;
                如果希望枚举停止,则应返回NO。
 @return 枚举对象
 */
- (nullable NSDirectoryEnumerator<NSURL *> *)enumeratorAtURL:(NSURL *)url
                                  includingPropertiesForKeys:(nullable NSArray<NSURLResourceKey> *)keys
                                                     options:(NSDirectoryEnumerationOptions)mask
                                                errorHandler:(nullable BOOL (^)(NSURL *url, NSError *error))handler;

subpathsAtPath:

/**
 返回指定目录所包含的所有文件和目录内容
 @param path 目标地址
 @return 包含的内容
 */
- (nullable NSArray<NSString *> *)subpathsAtPath:(NSString *)path;

contentsAtPath:

/**
 从文件中读取数据
 @param path 文件路径
 @return 文件数据
 */
- (nullable NSData *)contentsAtPath:(NSString *)path;

createFileAtPath:contents:attributes:

/**
 在给定位置创建具有指定内容和属性的文件(如果已存在会进行覆盖)
 @param path 文件路径
 @param data 文件内容
 @param attr 文件属性
 @return 如果操作成功或项目已存在返回YES,否则NO。
 */
- (BOOL)createFileAtPath:(NSString *)path
                contents:(nullable NSData *)data
              attributes:(nullable NSDictionary<NSFileAttributeKey, id> *)attr;

stringWithFileSystemRepresentation:length:

/**
 将C字符形式路径转化为NSString形式
 @param str C字符串表示形式的路径
 @param len 字符串中的字符数
 @return 转化后的路径
 */
- (NSString *)stringWithFileSystemRepresentation:(const char *)str
                                          length:(NSUInteger)len;

replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error

/**
 以确保不会发生数据丢失的方式替换指定URL处的项目内容。
 @param originalItemURL 被替换的项目
 @param newItemURL 		替换项目,建议您将此项目放在OS提供的临时目录中。
 						如果临时目录不可用,请将此项目放在与原始项目位于同一目录中的唯一命名目录中
 @param backupItemName 	如果提供,则用于创建原始项目备份的名称。
 @param options 		替换期间使用的选项
 @param resultingURL 	在输入时,是URL对象的指针。替换项目时,此指针将设置为新项目的URL。
 @param error 错误信息
 @return 操作结果
 */
- (BOOL)replaceItemAtURL:(NSURL *)originalItemURL
           withItemAtURL:(NSURL *)newItemURL
          backupItemName:(nullable NSString *)backupItemName
                 options:(NSFileManagerItemReplacementOptions)options
        resultingItemURL:(NSURL * _Nullable * _Nullable)resultingURL
                   error:(NSError **)error;

setUbiquitous:itemAtURL:destinationURL:error:

/**
 判断指定URL处的项目是否应存储在iCloud中。
 @param flag 		   YES,将项目移动到iCloud 或者 NO,将其从iCloud中移除(如果它当前存在)
 @param url 		   要存储在iCloud中的项目(文件或目录)的URL。
 @param destinationURL 将文件移动到iCloud中用于存储文件或目录的位置。
                       此URL必须由URLForUbiquityContainerIdentifier:方法返回的URL构造,该URL用于检索所需的iCloud容器目录。
                       您指定的URL可能包含其他子目录,以便您可以在iCloud中分层组织文件。
                       但是,您得负责在iCloud容器目录中创建这些中间子目录(使用NSFileManager类)。
                       将文件移出iCloud本地设备上的位置。
 @param error 		   错误信息
 @return 操作结果
 */
- (BOOL)setUbiquitous:(BOOL)flag
            itemAtURL:(NSURL *)url
       destinationURL:(NSURL *)destinationURL
                error:(NSError **)error;

isUbiquitousItemAtURL:

/**
 返回一个布尔值,判断该项是否以iCloud中的存储为目标。
 @param url 指定要检查其状态的文件或目录的URL。
 @return 判断结果
 */
- (BOOL)isUbiquitousItemAtURL:(NSURL *)url;

startDownloadingUbiquitousItemAtURL:error:

/**
 开始将指定iCloud项目下载(如有必要)到本地系统。
 @param url 	要下载的文件或目录的URL。
 @param error 	错误信息
 @return 是否可以下载
 */
- (BOOL)startDownloadingUbiquitousItemAtURL:(NSURL *)url
                                      error:(NSError **)error;

evictUbiquitousItemAtURL:error:

/**
 删除存储在iCloud中的指定项的本地副本。
 @param url 文件/目录URL
 @param error 错误信息
 @return 操作结果
 */
- (BOOL)evictUbiquitousItemAtURL:(NSURL *)url
                           error:(NSError **)error;

URLForUbiquityContainerIdentifier:

/**
 返回与指定标识符关联的iCloud容器的URL,并建立对该容器的访问权限。
 @param containerIdentifier iCloud容器目录的完全限定容器标识符
 @return 指向指定的ubiquity容器的URL,如果找不到容器,或者当前用户或设备的iCloud存储不可用,则为nil。
 */
- (nullable NSURL *)URLForUbiquityContainerIdentifier:(nullable NSString *)containerIdentifier;

URLForPublishingUbiquitousItemAtURL:expirationDate:error:

/**
 返回可以通过电子邮件发送给用户的URL,以允许他们从iCloud下载平面文件项的副本。
 @param url 	您要共享的iCloud项目的URL。
            	URL必须以从URLForUbiquityContainerIdentifier:方法返回的基本URL作为前缀,该URL对应于项目的位置。
			    该文件必须是平面文件,而不是捆绑包。调用此方法时,必须已将指定URL上的文件上载到iCloud。
 @param outDate 在输入时,指向日期对象的变量的指针。
                在输出时,此参数包含在返回的URL处不再提供该项目的日期。
                如果您对日期不感兴趣,可以为此参数指定nil。
 @param error 	错误信息
 @return 用户可以使用URL在URL上下载项目的副本。 如果由于任何原因无法创建URL,则返回nil。
 */
- (nullable NSURL *)URLForPublishingUbiquitousItemAtURL:(NSURL *)url
                                         expirationDate:(NSDate * _Nullable * _Nullable)outDate
                                                  error:(NSError **)error;

ubiquityIdentityToken

/** 一个不透明的标记,表示当前用户的iCloud标识。 */
@property (nullable, readonly, copy) id<NSObject,NSCopying,NSCoding> ubiquityIdentityToken;

getFileProviderServicesForItemAtURL:completionHandler:

/**
 返回由文件提供程序扩展提供的服务,该扩展管理给定URL处的项目。
 @param url 文档或目录的文件URL。
 @param completionHandler
        services:如果请求成功,则此属性包含具有零个或多个NSFileProviderServiceName键的字典及其对应的NSFileProviderService值; 否则,它被设置为零。
        error:错误信息
 */
- (void)getFileProviderServicesForItemAtURL:(NSURL *)url
                          completionHandler:(void (^)(NSDictionary <NSFileProviderServiceName, NSFileProviderService *> * _Nullable services, NSError * _Nullable error))completionHandler;

containerURLForSecurityApplicationGroupIdentifier:

/**
 返回与指定的安全应用程序组标识符关联的容器目录。
 @param groupIdentifier 一个字符串,用于命名要获取其共享目录的组。
                        此输入应与应用程序的com.apple.security.application-groups entitlements数组中的某个字符串完全匹配。
 @return 一个URL,指示组在文件系统中的共享目录的位置。
         在iOS中,当组标识符无效时,该值为nil。
         在macOS中,即使应用程序组无效,也始终返回预期表单的URL,因此请确保在尝试使用之前测试您是否可以访问基础目录。
 */
- (nullable NSURL *)containerURLForSecurityApplicationGroupIdentifier:(NSString *)groupIdentifier;

NSFileManager (NSUserInformation)

homeDirectoryForCurrentUser

/** 当前用户的主目录 */
@property (readonly, copy) NSURL *homeDirectoryForCurrentUser;

temporaryDirectory

/** 当前用户的临时目录 */
@property (readonly, copy) NSURL *temporaryDirectory;

homeDirectoryForUser:

/**
 返回指定用户的主目录
 @param userName 用户名
 @return URL地址
 */
- (nullable NSURL *)homeDirectoryForUser:(NSString *)userName;

NSFileManagerDelegate

fileManager:shouldCopyItemAtPath:toPath: fileManager:shouldCopyItemAtPath:toURL

/**
 是否应将指定的项目复制到新路径
 @param fileManager 文件管理器
 @param srcPath     源地址
 @param dstPath     目标地址
 @return 是否允许
 */
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldCopyItemAtPath:(NSString *)srcPath
             toPath:(NSString *)dstPath;
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldCopyItemAtURL:(NSURL *)srcURL
              toURL:(NSURL *)dstURL;

fileManager:shouldProceedAfterError:copyingItemAtURL:toPath: fileManager:shouldProceedAfterError:copyingItemAtURL:toURL:

/**
 在复制指定文件/目录时,发生错误后是否继续进行移动操作
 @param fileManager 文件管理器
 @param error       错误信息
 @param srcPath     源地址
 @param dstPath     目标地址
 @return 是否允许
 */
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldProceedAfterError:(NSError *)error
  copyingItemAtPath:(NSString *)srcPath
             toPath:(NSString *)dstPath;
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldProceedAfterError:(NSError *)error
   copyingItemAtURL:(NSURL *)srcURL
              toURL:(NSURL *)dstURL;

fileManager:shouldMoveItemAtPath:toPath: fileManager:shouldMoveItemAtPath:toURL:

/**
 是否应将指定的项目移动到新路径
 @param fileManager 文件管理器
 @param srcPath     源地址
 @param dstPath     目标地址
 @return 是否允许
 */
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldMoveItemAtPath:(NSString *)srcPath
             toPath:(NSString *)dstPath;
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldMoveItemAtURL:(NSURL *)srcURL
              toURL:(NSURL *)dstURL;

fileManager:shouldProceedAfterError:movingItemAtPath:toPath: fileManager:shouldProceedAfterError:movingItemAtPath:toURL:

/**
 在移动指定文件/目录时,发生错误后是否继续进行移动操作
 @param fileManager 文件管理器
 @param error       错误信息
 @param srcPath     源地址
 @param dstPath     目标地址
 @return 是否允许
 */
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldProceedAfterError:(NSError *)error
   movingItemAtPath:(NSString *)srcPath
             toPath:(NSString *)dstPath;
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldProceedAfterError:(NSError *)error
    movingItemAtURL:(NSURL *)srcURL
              toURL:(NSURL *)dstURL;

fileManager:shouldLinkItemAtPath:toPath: fileManager:shouldLinkItemAtPath:toURL:

/**
 是否应在两个路径的项目之间创建硬链接
 @param fileManager 文件管理器
 @param srcPath     源地址
 @param dstPath     目标地址
 @return 是否允许
 */
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldLinkItemAtPath:(NSString *)srcPath
             toPath:(NSString *)dstPath;
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldLinkItemAtURL:(NSURL *)srcURL
              toURL:(NSURL *)dstURL;

fileManager:shouldProceedAfterError:linkingItemAtPath:toPath: fileManager:shouldProceedAfterError:linkingItemAtPath:toURL:

/**
 在创建硬连接时,发生错误后是否继续进行操作
 @param fileManager 文件管理器
 @param error       错误信息
 @param srcPath     源地址
 @param dstPath     目标地址
 @return 是否允许
 */
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldProceedAfterError:(NSError *)error
  linkingItemAtPath:(NSString *)srcPath
             toPath:(NSString *)dstPath;
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldProceedAfterError:(NSError *)error
   linkingItemAtURL:(NSURL *)srcURL
              toURL:(NSURL *)dstURL;

fileManager:shouldRemoveItemAtPath: fileManager:shouldRemoveItemAtURL:

/**
 是否应将指定的项目移除
 @param fileManager 文件管理器
 @param path        源地址
 @return 是否允许
 */
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldRemoveItemAtPath:(NSString *)path;
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldRemoveItemAtURL:(NSURL *)URL;

fileManager:shouldProceedAfterError:removingItemAtPath: fileManager:shouldProceedAfterError:removingItemAtURL:

/**
 在进行删除时,发生错误后是否继续进行操作
 @param fileManager 文件管理器
 @param error       错误信息
 @param path        源地址
 @return 是否允许
 */
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldProceedAfterError:(NSError *)error
 removingItemAtPath:(NSString *)path;
- (BOOL)fileManager:(NSFileManager *)fileManager
shouldProceedAfterError:(NSError *)error
  removingItemAtURL:(NSURL *)URL;

NSDirectoryEnumerator : NSEnumerator

fileAttributes

/** 文件的文件属性字典 */
@property (nullable, readonly, copy) NSDictionary<NSFileAttributeKey, id> *fileAttributes;

directoryAttributes

/** 目录的文件属性字典 */
@property (nullable, readonly, copy) NSDictionary<NSFileAttributeKey, id> *directoryAttributes;

skipDescendents

/** 使接收者跳过递归到最近获得的子目录 */
- (void)skipDescendents;

level

/** 当前对象在枚举的目录层次结构中的深度级别 */
@property (readonly) NSUInteger level;

skipDescendants

/** 使接收者跳过递归到最近获得的子目录,上面的方法拼写错误,但一样能用 */
- (void)skipDescendants;

NSFileAttributeType

keydescription
NSFileType文件属性字典中的键,其值表示文件的类型
NSFileTypeDirectory一个目录
NSFileTypeRegular常规文件
NSFileTypeSymbolicLink快捷方式
NSFileTypeSocketsocket
NSFileTypeCharacterSpecial特殊字符文件
NSFileTypeBlockSpecial特殊block文件
NSFileTypeUnknown未知类型

NSFileAttributeType

keydescription
NSFileSize表示文件的大小(以字节为单位)
NSFileModificationDate表示文件上次修改的日期
NSFileReferenceCount表示文件的引用计数
NSFileDeviceIdentifier表示文件所在的设备的标识符
NSFileOwnerAccountName表示文件所有者的名称
NSFileGroupOwnerAccountName表示文件所有者的组名
NSFilePosixPermissions表示文件的Posix权限
NSFileSystemNumber表示文件系统的文件系统编号
NSFileSystemFileNumber表示文件的文件系统文件编号
NSFileExtensionHidden表示文件的扩展名是否隐藏
NSFileHFSCreatorCode表示文件的HFS创建者代码
NSFileHFSTypeCode表示文件的HFS类型代码
NSFileImmutable表示文件是否可变
NSFileAppendOnly表示文件是否为只读
NSFileCreationDate表示文件的创建日期
NSFileOwnerAccountID表示文件所有者的帐户ID
NSFileGroupOwnerAccountID表示文件的组ID
NSFileBusy表示文件是否繁忙
NSFileProtectionKey表示此文件的保护级别
NSFileSystemSize表示文件系统的大小
NSFileSystemFreeSize表示文件系统上的可用空间量
NSFileSystemNodes表示文件系统中的节点数
NSFileSystemFreeNodes表示文件系统中的空闲节点数

NSFileProtectionType

keydescription
NSFileProtectionNone该文件没有与之相关的特殊保护
NSFileProtectionComplete该文件以加密格式存储在磁盘上,在设备锁定或引导时无法读取或写入
NSFileProtectionCompleteUnlessOpen关闭后,文件以加密格式存储在磁盘上
NSFileProtectionCompleteUntilFirstUserAuthentication该文件以加密格式存储在磁盘上,直到设备启动后才能访问
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值