用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/csharpfritz/MyFirstTextGame --skill directory-tree-path-resolution命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | directory-tree-path-resolution |
| description | Walk up directory tree to resolve resource paths for dev and distribution |
| domain | file-system |
| confidence | low |
| source | earned |
Applications often need to find resource files (configs, data, assets) that exist at project root during development but may be in different locations when distributed. Walking up the directory tree provides a robust fallback that works in both scenarios.
When a relative path might exist in an ancestor directory, walk up from the executable location checking each level. This handles:
AppContext.BaseDirectory (or equivalent)// C# .NET implementation
static string? ResolveWorldPath(string relativePath)
{
// Walk up from exe directory to find worlds folder (for dev runs)
var current = new DirectoryInfo(AppContext.BaseDirectory);
while (current != null)
{
var candidate = Path.Combine(current.FullName, relativePath);
if (File.Exists(candidate))
return candidate;
current = current.Parent;
}
return null;
}
// Usage
var worldPath = "worlds/game/world.json";
if (!Path.IsPathRooted(worldPath))
{
var resolved = ResolveWorldPath(worldPath);
worldPath = resolved ?? Path.Combine(AppContext.BaseDirectory, worldPath);
}
// Node.js implementation
function resolveResourcePath(relativePath) {
let current = __dirname;
while (current) {
const candidate = path.join(current, relativePath);
if (fs.existsSync(candidate)) {
return candidate;
}
const parent = path.dirname(current);
if (parent === current) break; // Reached root
current = parent;
}
return null;
}
# Python implementation
def resolve_resource_path(relative_path):
current = Path(__file__).parent
while current != current.parent:
candidate = current / relative_path
if candidate.exists():
return candidate
current = current.parent
return None