讓龍蝦幫你自動盤點電腦裡的檔案!
1Top 大檔 - 找出佔用空間最多的檔案(預設 Top 30)
2最近修改 - 列出最近修改的檔案(Top 30)
3副檔名統計 - 統計各種副檔名的總容量(Top 30)
4重複檔偵測 - 用 SHA256 雜湊找出重複的檔案
在 PowerShell 執行以下指令,建立 skill 資料夾:
# 建立 skill 資料夾結構 mkdir "$env:USERPROFILE\.openclaw\workspace\skills\disk-audit\scripts" -Force # 建立報告輸出資料夾 mkdir "$env:USERPROFILE\.openclaw\workspace\reports\disk-audit" -Force
.openclaw/workspace/skills/disk-audit/ - Skill 主資料夾.openclaw/workspace/skills/disk-audit/scripts/ - 腳本資料夾.openclaw/workspace/reports/disk-audit/ - 報告輸出資料夾
在 disk-audit 資料夾建立 SKILL.md 檔案:
# disk-audit 磁碟常態盤點/整理工具 ## 功能 - 掃描指定資料夾,產出盤點報告 - 找出大檔案、最近修改、副檔名統計、重複檔 ## 設定 - 掃描範圍:C:\Users\user\Downloads + C:\Users\user\Desktop - 大檔門檻:500MB - 排程:手動執行(說「跑磁碟盤點」) ## 使用方式 跟龍蝦說:「跑磁碟盤點」 ## 報告位置 .openclaw/workspace/reports/disk-audit/YYYY-MM-DD.md
在 scripts 資料夾建立 scan.ps1:
# disk-audit scan.ps1
# 磁碟盤點掃描腳本
param(
[string[]]$ScanPaths = @(
"$env:USERPROFILE\Downloads",
"$env:USERPROFILE\Desktop"
),
[int]$LargeFileMB = 500,
[int]$TopN = 30
)
$reportDate = Get-Date -Format "yyyy-MM-dd"
$reportPath = "$env:USERPROFILE\.openclaw\workspace\reports\disk-audit\$reportDate.md"
# 排除的系統資料夾
$excludeDirs = @("Windows", "Program Files", "Program Files (x86)",
'$Recycle.Bin', "node_modules", ".git")
Write-Host "開始掃描..." -ForegroundColor Cyan
# 取得所有檔案
$allFiles = @()
foreach ($path in $ScanPaths) {
if (Test-Path $path) {
$allFiles += Get-ChildItem -Path $path -Recurse -File -ErrorAction SilentlyContinue |
Where-Object {
$dominated = $false
foreach ($ex in $excludeDirs) {
if ($_.FullName -like "*\$ex\*") { $dominated = $true; break }
}
-not $dominated
}
}
}
# 產生報告
$report = "# 磁碟盤點報告 - $reportDate`n`n"
# Top 大檔
$report += "## Top $TopN 大檔案`n"
$largeFiles = $allFiles | Sort-Object Length -Descending | Select-Object -First $TopN
foreach ($f in $largeFiles) {
$sizeMB = [math]::Round($f.Length / 1MB, 2)
$report += "- $sizeMB MB - $($f.FullName)`n"
}
# 儲存報告
$report | Out-File -FilePath $reportPath -Encoding UTF8
Write-Host "報告已產生:$reportPath" -ForegroundColor Green
| 參數 | 說明 | 預設值 |
|---|---|---|
$ScanPaths |
要掃描的資料夾路徑(可多個) | Downloads + Desktop |
$LargeFileMB |
大檔門檻(多少 MB 算大檔) | 500 MB |
$TopN |
顯示前幾名 | 30 |
$excludeDirs |
排除的資料夾 | Windows, node_modules 等 |
跑磁碟盤點
龍蝦會自動執行 scan.ps1 並產出報告。
# 在 PowerShell 執行 & "$env:USERPROFILE\.openclaw\workspace\skills\disk-audit\scripts\scan.ps1"
# 掃描 D 槽的 Videos 資料夾
& "$env:USERPROFILE\.openclaw\workspace\skills\disk-audit\scripts\scan.ps1" `
-ScanPaths @("D:\Videos") -LargeFileMB 1000
# 磁碟盤點報告 - 2026-02-05 ## Top 30 大檔案 - 4521.32 MB - D:\Videos\movie.mkv - 2103.45 MB - C:\Users\user\Downloads\software.iso - 1892.11 MB - D:\Backup\archive.zip - 856.23 MB - C:\Users\user\Desktop\presentation.pptx ... ## 最近修改 Top 30 - 2026-02-05 10:30 - C:\Users\user\Documents\report.docx - 2026-02-05 09:15 - C:\Users\user\Downloads\data.xlsx ... ## 副檔名容量統計 | 副檔名 | 總容量 | 檔案數 | |--------|--------|--------| | .mkv | 15.2 GB | 12 | | .mp4 | 8.7 GB | 45 | | .zip | 3.2 GB | 28 |
在 scan.ps1 加入以下程式碼:
# 重複檔偵測(用檔案大小分組,再用 SHA256 比對)
$report += "`n## 可能的重複檔案`n"
$sizeGroups = $allFiles | Group-Object Length | Where-Object { $_.Count -gt 1 }
$duplicates = @()
foreach ($group in $sizeGroups | Select-Object -First 50) {
$hashes = @{}
foreach ($file in $group.Group) {
$hash = (Get-FileHash $file.FullName -Algorithm SHA256).Hash
if ($hashes.ContainsKey($hash)) {
$duplicates += [PSCustomObject]@{
Hash = $hash
File1 = $hashes[$hash]
File2 = $file.FullName
Size = $file.Length
}
} else {
$hashes[$hash] = $file.FullName
}
}
}
foreach ($dup in $duplicates) {
$sizeMB = [math]::Round($dup.Size / 1MB, 2)
$report += "- [$sizeMB MB] 重複:`n"
$report += " - $($dup.File1)`n"
$report += " - $($dup.File2)`n"
}
現在你可以跟龍蝦說「跑磁碟盤點」來產生報告了!