API参考Foundation

NSFileManager

文件系统操作,检查路径、创建目录、读写文件等。

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

类成员 (Class members)

defaultManager

获取默认文件管理器。

static defaultManager(): NSFileManager

Return Value:

  • NSFileManager: 默认单例。

实例成员 (Instance members)

路径与目录

fileExistsAtPath

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

fileExistsAtPath(path: string): boolean

Parameters:

NameTypeDescription
pathstring文件或目录路径。

isDirectoryAtPath

检查路径是否为目录。

isDirectoryAtPath(path: string): boolean

Parameters:

NameTypeDescription
pathstring路径。

createDirectoryAtPathWithIntermediateDirectoriesAttributes

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

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

Parameters:

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

createDirectoryAtPathAttributes (简易版)

创建目录(简易版)。

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

Parameters:

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

contentsOfDirectoryAtPath

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

contentsOfDirectoryAtPath(path: string): string[]

Parameters:

NameTypeDescription
pathstring目录路径。

Return Value:

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

subpathsOfDirectoryAtPath

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

subpathsOfDirectoryAtPath(path: string): string[]

Parameters:

NameTypeDescription
pathstring目录路径。

subpathsAtPath

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

subpathsAtPath(path: string): string[]

Parameters:

NameTypeDescription
pathstring路径。

directoryContentsAtPath

获取目录内容(旧 API)。

directoryContentsAtPath(path: string): string[]

Parameters:

NameTypeDescription
pathstring目录路径。

读写与复制

contentsAtPath

读取文件内容。

contentsAtPath(path: string): NSData

Parameters:

NameTypeDescription
pathstring文件路径。

Return Value:

  • NSData: 文件数据对象。

copyItemAtPathToPath

复制文件或目录。

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

Parameters:

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

moveItemAtPathToPath

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

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

Parameters:

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

属性与权限

attributesOfItemAtPath

获取文件/目录属性。

attributesOfItemAtPath(path: string): NSDictionary

Parameters:

NameTypeDescription
pathstring路径。

attributesOfFileSystemForPath

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

attributesOfFileSystemForPath(path: string): NSDictionary

Parameters:

NameTypeDescription
pathstring路径。

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

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

Parameters:

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

isReadableFileAtPath

检查文件是否可读。

isReadableFileAtPath(path: string): boolean

isWritableFileAtPath

检查文件是否可写。

isWritableFileAtPath(path: string): boolean

isExecutableFileAtPath

检查文件是否可执行。

isExecutableFileAtPath(path: string): boolean

isDeletableFileAtPath

检查文件是否可删除。

isDeletableFileAtPath(path: string): boolean

相关

头文件API清单

正在加载...

协议:JSBNSFileManager,来源:-