Skip to content

NSFileManager

用于文件系统操作。通过 NSFileManager.defaultManager() 获取默认实例。常与 Application.documentPathApplication.tempPath 配合使用。

方法返回值说明
static defaultManager()NSFileManager获取默认文件管理器。
方法参数返回值说明
fileExistsAtPath(path)path: stringboolean检查文件或目录是否存在。
isDirectoryAtPath(path)path: stringboolean是否为目录。
createDirectoryAtPath(path, withIntermediateDirectories, attributes)path, createIntermediates: boolean, attributes: NSDictionary | nullboolean创建目录。
createDirectoryAtPath(path, attributes)path, attributesboolean创建单级目录。
contentsOfDirectoryAtPath(path)path: stringstring[]目录内容(文件名列表)。
subpathsOfDirectoryAtPath(path)path: stringstring[]子路径列表。
subpathsAtPath(path)path: stringstring[]同上。
directoryContentsAtPath(path)path: stringstring[]目录内容。
方法参数返回值说明
contentsAtPath(path)path: stringNSData读取文件为 NSData。
copyItemAtPath(srcPath, toPath)srcPath, dstPath: stringboolean复制文件/目录。
moveItemAtPath(srcPath, toPath)srcPath, dstPath: stringboolean移动。
方法说明
attributesOfItemAtPath(path)获取项属性。
attributesOfFileSystemForPath(path)获取文件系统属性。
fileAttributesAtPath(path, traverseLink)文件属性。
isReadableFileAtPath(path) / isWritableFileAtPath(path) / isExecutableFileAtPath(path) / isDeletableFileAtPath(path)权限检查。