NSFileManager
用于文件系统操作。通过 NSFileManager.defaultManager() 获取默认实例。常与 Application.documentPath、Application.tempPath 配合使用。
类成员 (Class members)
Section titled “类成员 (Class members)”defaultManager
Section titled “defaultManager”获取默认文件管理器。
static defaultManager(): NSFileManagerReturn Value:
NSFileManager: 默认单例。
实例成员 (Instance members)
Section titled “实例成员 (Instance members)”fileExistsAtPath
Section titled “fileExistsAtPath”检查文件或目录是否存在。
fileExistsAtPath(path: string): booleanParameters:
| Name | Type | Description |
|---|---|---|
path | string | 文件或目录路径。 |
isDirectoryAtPath
Section titled “isDirectoryAtPath”检查路径是否为目录。
isDirectoryAtPath(path: string): booleanParameters:
| Name | Type | Description |
|---|---|---|
path | string | 路径。 |
createDirectoryAtPathWithIntermediateDirectoriesAttributes
Section titled “createDirectoryAtPathWithIntermediateDirectoriesAttributes”创建目录(支持创建中间目录)。
createDirectoryAtPathWithIntermediateDirectoriesAttributes(path: string, withIntermediateDirectories: boolean, attributes: NSDictionary | null): booleanParameters:
| Name | Type | Description |
|---|---|---|
path | string | 目录路径。 |
withIntermediateDirectories | boolean | 是否创建中间目录。 |
attributes | NSDictionary | null | 目录属性(通常传 null)。 |
createDirectoryAtPathAttributes (简易版)
Section titled “createDirectoryAtPathAttributes (简易版)”创建目录(简易版)。
createDirectoryAtPathAttributes(path: string, attributes: NSDictionary | null): booleanParameters:
| Name | Type | Description |
|---|---|---|
path | string | 目录路径。 |
attributes | NSDictionary | null | 目录属性。 |
contentsOfDirectoryAtPath
Section titled “contentsOfDirectoryAtPath”获取目录内容(浅层遍历)。
contentsOfDirectoryAtPath(path: string): string[]Parameters:
| Name | Type | Description |
|---|---|---|
path | string | 目录路径。 |
Return Value:
string[]: 文件名/子目录名列表。
subpathsOfDirectoryAtPath
Section titled “subpathsOfDirectoryAtPath”获取目录的所有子路径(深层遍历)。
subpathsOfDirectoryAtPath(path: string): string[]Parameters:
| Name | Type | Description |
|---|---|---|
path | string | 目录路径。 |
subpathsAtPath
Section titled “subpathsAtPath”获取路径下的所有子路径。
subpathsAtPath(path: string): string[]Parameters:
| Name | Type | Description |
|---|---|---|
path | string | 路径。 |
directoryContentsAtPath
Section titled “directoryContentsAtPath”获取目录内容(旧 API)。
directoryContentsAtPath(path: string): string[]Parameters:
| Name | Type | Description |
|---|---|---|
path | string | 目录路径。 |
contentsAtPath
Section titled “contentsAtPath”读取文件内容。
contentsAtPath(path: string): NSDataParameters:
| Name | Type | Description |
|---|---|---|
path | string | 文件路径。 |
Return Value:
NSData: 文件数据对象。
copyItemAtPathToPath
Section titled “copyItemAtPathToPath”复制文件或目录。
copyItemAtPathToPath(srcPath: string, toPath: string): booleanParameters:
| Name | Type | Description |
|---|---|---|
srcPath | string | 源路径。 |
toPath | string | 目标路径。 |
moveItemAtPathToPath
Section titled “moveItemAtPathToPath”移动(重命名)文件或目录。
moveItemAtPathToPath(srcPath: string, toPath: string): booleanParameters:
| Name | Type | Description |
|---|---|---|
srcPath | string | 源路径。 |
toPath | string | 目标路径。 |
attributesOfItemAtPath
Section titled “attributesOfItemAtPath”获取文件/目录属性。
attributesOfItemAtPath(path: string): NSDictionaryParameters:
| Name | Type | Description |
|---|---|---|
path | string | 路径。 |
attributesOfFileSystemForPath
Section titled “attributesOfFileSystemForPath”获取文件系统属性(如磁盘空间)。
attributesOfFileSystemForPath(path: string): NSDictionaryParameters:
| Name | Type | Description |
|---|---|---|
path | string | 路径。 |
fileAttributesAtPathTraverseLink
Section titled “fileAttributesAtPathTraverseLink”获取文件属性(遍历符号链接选项)。
fileAttributesAtPathTraverseLink(path: string, traverseLink: boolean): NSDictionaryParameters:
| Name | Type | Description |
|---|---|---|
path | string | 路径。 |
traverseLink | boolean | 是否跟随符号链接。 |
isReadableFileAtPath
Section titled “isReadableFileAtPath”检查文件是否可读。
isReadableFileAtPath(path: string): booleanisWritableFileAtPath
Section titled “isWritableFileAtPath”检查文件是否可写。
isWritableFileAtPath(path: string): booleanisExecutableFileAtPath
Section titled “isExecutableFileAtPath”检查文件是否可执行。
isExecutableFileAtPath(path: string): booleanisDeletableFileAtPath
Section titled “isDeletableFileAtPath”检查文件是否可删除。
isDeletableFileAtPath(path: string): boolean