# Vault-Para 结构扫描脚本 # 用法: 在 my-vault 目录中运行此脚本 # 输出: 在当前目录生成 vault-para-scan-report.md $vaultParaPath = "D:\tmp\vault\vault-para" $reportPath = ".\vault-para-scan-report.md" Write-Host "正在扫描 vault-para 结构..." -ForegroundColor Green Write-Host "目标路径: $vaultParaPath" -ForegroundColor Cyan # 检查路径是否存在 if (-not (Test-Path $vaultParaPath)) { Write-Host "❌ 错误: 找不到 vault-para 目录: $vaultParaPath" -ForegroundColor Red exit 1 } Push-Location $vaultParaPath # 初始化报告 $report = @" # Vault-Para 扫描报告 扫描时间: $(Get-Date -Format "yyyy-MM-dd HH:mm:ss") 扫描路径: $vaultParaPath --- ## 📊 统计概览 "@ # 统计信息 $mdFiles = Get-ChildItem -Recurse -Filter "*.md" -File $allFiles = Get-ChildItem -Recurse -File $directories = Get-ChildItem -Recurse -Directory $report += @" - **Markdown 文件**: $($mdFiles.Count) - **总文件数**: $($allFiles.Count) - **目录数**: $($directories.Count) "@ # 文件类型统计 $report += "`n## 📁 文件类型分布`n`n" $fileTypes = $allFiles | Group-Object Extension | Sort-Object Count -Descending | Select-Object -First 10 $report += "| 扩展名 | 数量 |`n" $report += "|--------|------|`n" foreach ($type in $fileTypes) { $ext = if ($type.Name) { $type.Name } else { "(无扩展名)" } $report += "| $ext | $($type.Count) |`n" } # 目录结构(完整树形) $report += "`n## 🌳 完整目录结构`n`n" $report += "``````text`n" function Get-TreeStructure { param($Path, $Prefix = "", $IsLast = $true) $items = Get-ChildItem -Path $Path | Sort-Object { $_.PSIsContainer }, Name $total = $items.Count for ($i = 0; $i -lt $total; $i++) { $item = $items[$i] $isLastItem = ($i -eq ($total - 1)) $connector = if ($isLastItem) { "└── " } else { "├── " } $itemName = if ($item.PSIsContainer) { "$($item.Name)/" } else { $item.Name } "$Prefix$connector$itemName" if ($item.PSIsContainer) { $newPrefix = if ($isLastItem) { "$Prefix " } else { "$Prefix│ " } Get-TreeStructure -Path $item.FullName -Prefix $newPrefix -IsLast $isLastItem } } } Get-TreeStructure -Path $vaultParaPath | Out-String | ForEach-Object { $report += $_ } $report += "``````n`n" # 顶层内容详情 $report += "`n## 📂 顶层目录详情`n`n" $topLevel = Get-ChildItem | Sort-Object { $_.PSIsContainer }, Name foreach ($item in $topLevel) { if ($item.PSIsContainer) { $filesInDir = (Get-ChildItem -Path $item.FullName -Recurse -File).Count $mdInDir = (Get-ChildItem -Path $item.FullName -Recurse -Filter "*.md" -File).Count $report += "### 📁 $($item.Name)/`n" $report += "- 总文件: $filesInDir`n" $report += "- Markdown: $mdInDir`n" # 列出子目录 $subDirs = Get-ChildItem -Path $item.FullName -Directory if ($subDirs.Count -gt 0) { $report += "- 子目录: " + ($subDirs.Name -join ", ") + "`n" } $report += "`n" } } # Markdown 文件列表(按目录组织) $report += "`n## 📝 Markdown 文件清单`n`n" $mdByDir = $mdFiles | Group-Object { $_.DirectoryName } | Sort-Object Name foreach ($group in $mdByDir) { $relPath = $group.Name.Replace($vaultParaPath, ".").Replace("\", "/") $report += "### $relPath`n" foreach ($file in ($group.Group | Sort-Object Name)) { $size = [math]::Round($file.Length / 1KB, 2) $report += "- $($file.Name) ($size KB)`n" } $report += "`n" } # 检查是否有 frontmatter $report += "`n## 🏷️ Frontmatter 采样(前10个文件)`n`n" $sampleFiles = $mdFiles | Select-Object -First 10 foreach ($file in $sampleFiles) { $content = Get-Content $file.FullName -Raw -Encoding UTF8 if ($content -match '^---\s*\n(.*?)\n---') { $frontmatter = $matches[1] $report += "**$($file.Name)**:`n``````yaml`n$frontmatter`n```````n`n" } } # 检查内部链接模式 $report += "`n## 🔗 链接模式采样`n`n" $linkPatterns = @{ "WikiLinks" = 0 "MarkdownLinks" = 0 "Tags" = 0 } foreach ($file in ($mdFiles | Select-Object -First 50)) { $content = Get-Content $file.FullName -Raw -Encoding UTF8 if ($content -match '\[\[.*?\]\]') { $linkPatterns["WikiLinks"]++ } if ($content -match '\[.*?\]\(.*?\)') { $linkPatterns["MarkdownLinks"]++ } if ($content -match '#\w+') { $linkPatterns["Tags"]++ } } $report += "在前50个文件中发现:`n" $report += "- WikiLinks `[[]]`: $($linkPatterns["WikiLinks"]) 个文件`n" $report += "- Markdown Links `[]()`: $($linkPatterns["MarkdownLinks"]) 个文件`n" $report += "- Tags `#tag`: $($linkPatterns["Tags"]) 个文件`n" Pop-Location # 保存报告到 my-vault $fullReportPath = Join-Path (Get-Location) $reportPath $report | Out-File -FilePath $fullReportPath -Encoding UTF8 Write-Host "`n✅ 扫描完成!" -ForegroundColor Green Write-Host "报告已保存到: $fullReportPath" -ForegroundColor Cyan Write-Host "`n下一步: 让 Claude 分析报告并制定迁移计划。" -ForegroundColor Yellow