Skip to content

NSFileManager

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

获取默认文件管理器。

static defaultManager(): NSFileManager

Return Value:

  • NSFileManager: 默认单例。

检查文件或目录是否存在。

fileExistsAtPath(path: string): boolean

Parameters:

NameTypeDescription
pathstring文件或目录路径。

检查路径是否为目录。

isDirectoryAtPath(path: string): boolean

Parameters:

NameTypeDescription
pathstring路径。

createDirectoryAtPathWithIntermediateDirectoriesAttributes

Section titled “createDirectoryAtPathWithIntermediateDirectoriesAttributes”

创建目录(支持创建中间目录)。

createDirectoryAtPathWithIntermediateDirectoriesAttributes(path: string, withIntermediateDirectories: boolean, attributes: NSDictionary | null): boolean

Parameters:

NameTypeDescription
pathstring目录路径。
withIntermediateDirectoriesboolean是否创建中间目录。
attributesNSDictionary | null目录属性(通常传 null)。

createDirectoryAtPathAttributes (简易版)

Section titled “createDirectoryAtPathAttributes (简易版)”

创建目录(简易版)。

createDirectoryAtPathAttributes(path: string, attributes: NSDictionary | null): boolean

Parameters:

NameTypeDescription
pathstring目录路径。
attributesNSDictionary | null目录属性。

获取目录内容(浅层遍历)。

contentsOfDirectoryAtPath(path: string): string[]

Parameters:

NameTypeDescription
pathstring目录路径。

Return Value:

  • string[]: 文件名/子目录名列表。

获取目录的所有子路径(深层遍历)。

subpathsOfDirectoryAtPath(path: string): string[]

Parameters:

NameTypeDescription
pathstring目录路径。

获取路径下的所有子路径。

subpathsAtPath(path: string): string[]

Parameters:

NameTypeDescription
pathstring路径。

获取目录内容(旧 API)。

directoryContentsAtPath(path: string): string[]

Parameters:

NameTypeDescription
pathstring目录路径。

读取文件内容。

contentsAtPath(path: string): NSData

Parameters:

NameTypeDescription
pathstring文件路径。

Return Value:

  • NSData: 文件数据对象。

复制文件或目录。

copyItemAtPathToPath(srcPath: string, toPath: string): boolean

Parameters:

NameTypeDescription
srcPathstring源路径。
toPathstring目标路径。

移动(重命名)文件或目录。

moveItemAtPathToPath(srcPath: string, toPath: string): boolean

Parameters:

NameTypeDescription
srcPathstring源路径。
toPathstring目标路径。

获取文件/目录属性。

attributesOfItemAtPath(path: string): NSDictionary

Parameters:

NameTypeDescription
pathstring路径。

获取文件系统属性(如磁盘空间)。

attributesOfFileSystemForPath(path: string): NSDictionary

Parameters:

NameTypeDescription
pathstring路径。

获取文件属性(遍历符号链接选项)。

fileAttributesAtPathTraverseLink(path: string, traverseLink: boolean): NSDictionary

Parameters:

NameTypeDescription
pathstring路径。
traverseLinkboolean是否跟随符号链接。

检查文件是否可读。

isReadableFileAtPath(path: string): boolean

检查文件是否可写。

isWritableFileAtPath(path: string): boolean

检查文件是否可执行。

isExecutableFileAtPath(path: string): boolean

检查文件是否可删除。

isDeletableFileAtPath(path: string): boolean
头文件 API 清单

正在加载…

协议:,来源: