cangjie-fs
Reference for Cangjie language file system interactions including read, write, and directory management.
Install
mkdir -p .claude/skills/cangjie-fs && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/18452" && unzip -o skill.zip -d .claude/skills/cangjie-fs && rm skill.zipInstalls to .claude/skills/cangjie-fs
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
仓颉语言文件系统操作。当需要了解仓颉语言的文件读写(File)、目录操作(Directory)、路径处理(Path)、文件信息(FileInfo)、文件系统函数(exists/copy/rename/remove)等特性时,应使用此 Skill。Key capabilities
- →Perform file read and write operations using `File` class
- →Manage directories with `Directory` operations
- →Handle paths using `Path` structure
- →Retrieve file information with `FileInfo`
- →Utilize file system functions like `exists`, `copy`, `rename`, `remove`
- →Automatically close files using `try-with-resource`
How it works
The skill provides documentation and code patterns for Cangjie's file system operations, including file, directory, and path management, and utility functions.
Inputs & outputs
When to use cangjie-fs
- →Reading and writing files in Cangjie
- →Creating recursive directories
- →Moving or renaming files in a Cangjie project
About this skill
仓颉语言文件系统 Skill
1. File 类
- 来自
std.fs.* - 实现
Resource & IOStream & Seekable - 构造:
File(path, OpenMode)或File(Path, OpenMode)
| 打开模式 | 行为 |
|---|---|
Read | 只读,文件不存在抛异常 |
Write | 只写,存在则截断,不存在则创建 |
Append | 追加写,不存在则创建 |
ReadWrite | 读写,不存在则创建,不截断 |
- 静态方法:
| 方法 | 说明 |
|---|---|
File.create(path) | 创建文件,返回只写 File |
File.createTemp(dirPath) | 创建临时文件 |
File.readFrom(path): Array<Byte> | 一次性读取整个文件 |
File.writeTo(path, data) | 一次性写入整个文件 |
File.appendTo(path, data) | 追加写入 |
- 使用
try-with-resource自动关闭
import std.fs.*
import std.io.*
main() {
let path = Path("./demo.txt")
// 写入文件
try (f = File(path, Write)) {
f.write("Hello 仓颉\n".toArray())
}
// 追加
File.appendTo(path, "第二行\n".toArray())
// 读取整个文件
let data = File.readFrom(path)
println(String.fromUtf8(data))
// 随机读取
try (f = File(path, Read)) {
f.seek(SeekPosition.Begin(6))
let buf = Array<Byte>(6, repeat: 0)
f.read(buf)
println(String.fromUtf8(buf))
}
remove(path)
}
2. 文件系统函数
| 函数 | 说明 |
|---|---|
exists(path): Bool | 检查文件/目录是否存在 |
copy(src, to: dst, overwrite) | 复制文件或目录 |
rename(src, to: dst, overwrite) | 重命名/移动 |
remove(path, recursive) | 删除文件或目录 |
removeIfExists(path, recursive) | 安全删除(不存在不报错) |
3. Directory 操作
| 方法 | 说明 |
|---|---|
Directory.create(path, recursive) | 创建目录,recursive: true 递归创建 |
Directory.createTemp(dirPath) | 创建临时目录 |
Directory.isEmpty(path): Bool | 检查目录是否为空 |
Directory.readFrom(path): Array<FileInfo> | 列出目录内容 |
Directory.walk(path, callback) | 遍历目录(回调返回 false 停止) |
import std.fs.*
main() {
let dir = Path("./mydir/sub")
Directory.create(dir, recursive: true)
File.create(dir.join("test.txt")).close()
let entries = Directory.readFrom(Path("./mydir"))
for (e in entries) {
println("${e.name} - ${e.size} bytes")
}
remove(Path("./mydir"), recursive: true)
}
4. Path 操作
Path是路径结构体,支持路径拼接和解析- 关键属性:
parent、fileName、extensionName、fileNameWithoutExtension、isAbsolute() path.join(subPath)— 拼接子路径canonicalize(path)— 解析为绝对规范路径(处理.、..、符号链接)
import std.fs.*
main() {
let p = Path("/home/user/docs/readme.md")
println(p.parent) // "/home/user/docs"
println(p.fileName) // "readme.md"
println(p.extensionName) // "md"
println(p.fileNameWithoutExtension) // "readme"
println(p.isAbsolute()) // true
println(p.join("../notes")) // "/home/user/docs/readme.md/../notes"
println(canonicalize(Path("."))) // 当前目录的绝对路径
}
5. FileInfo
- 通过
File.info或Directory.readFrom()获取 - 属性:
name、path、size、creationTime、lastAccessTime、lastModificationTime、parentDirectory - 注意:每次访问属性都从文件系统实时获取,注意并发竞态
6. 异常类型
| 异常 | 说明 |
|---|---|
FSException | 文件系统错误(继承自 IOException) |
7. 关键规则速查
- 文件使用
try-with-resource自动关闭 File.readFrom/File.writeTo/File.appendTo是便捷的一次性读写方法FileInfo每次属性访问都是实时文件系统查询,注意并发竞态Directory.create需要recursive: true才能递归创建多级目录remove删除目录时需要recursive: true
When not to use it
- →When not working with Cangjie language file system operations
Limitations
- →The skill is specific to the Cangjie language
- →The skill focuses on `std.fs.*` components
- →The skill notes that `FileInfo` attribute access is real-time
How it compares
This skill offers specific guidance and examples for Cangjie's file system API, providing direct solutions unlike general programming language file handling.
Compared to similar skills
cangjie-fs side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| cangjie-fs (this skill) | 0 | 4mo | No flags | Intermediate |
| fastapi-templates | 520 | 2mo | No flags | Intermediate |
| android-kotlin-development | 268 | 4mo | Review | Advanced |
| unity-developer | 142 | 3mo | No flags | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
fastapi-templates
wshobson
Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.
android-kotlin-development
aj-geddes
Develop native Android apps with Kotlin. Covers MVVM with Jetpack, Compose for modern UI, Retrofit for API calls, Room for local storage, and navigation architecture.
unity-developer
sickn33
Build Unity games with optimized C# scripts, efficient rendering, and proper asset management. Masters Unity 6 LTS, URP/HDRP pipelines, and cross-platform deployment. Handles gameplay systems, UI implementation, and platform optimization. Use PROACTIVELY for Unity performance issues, game mechanics, or cross-platform builds.
supabase-developer
daffy0208
Build full-stack applications with Supabase (PostgreSQL, Auth, Storage, Real-time, Edge Functions). Use when implementing authentication, database design with RLS, file storage, real-time features, or serverless functions.
payload
payloadcms
Use when working with Payload CMS projects (payload.config.ts, collections, fields, hooks, access control, Payload API). Use when debugging validation errors, security issues, relationship queries, transactions, or hook behavior.
architecture-patterns
wshobson
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use when architecting complex backend systems or refactoring existing applications for better maintainability.