Created
February 26, 2025 09:34
-
-
Save Broxzier/c8fb20d46ce634b86d177edf21340dc8 to your computer and use it in GitHub Desktop.
PowerShell script that iterates over all .meta files in the given directory (defaults to the parent working directory) to scan for duplicate GUIDs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter(Position = 0)] | |
[string]$FolderPath = $pwd.Path | |
) | |
Write-Host "Scanning for duplicate GUIDs. Please wait..." | |
# Find all .meta files recursively within the specified folder | |
$metaFiles = Get-ChildItem -Path $FolderPath -Filter "*.meta" -Recurse | |
# Loop through each .meta file and extract the GUIDs into an array | |
$guids = @() | |
foreach ($file in $metaFiles) { | |
try { | |
$content = Get-Content -LiteralPath $file.FullName | |
foreach ($line in $content) { | |
if ($line -match "^guid: ([0-9a-fA-F]{32})$") { | |
$guids += $Matches[1] | |
} | |
} | |
} | |
catch { | |
Write-Warning "Error reading file: $($file.FullName): $($_.Exception.Message)" | |
} | |
} | |
# Group the GUIDs and count occurrences | |
$groupedGuids = $guids | Group-Object | |
# Output duplicate GUIDs | |
$foundDuplicates = $false | |
foreach ($group in $groupedGuids) { | |
if ($group.Count -gt 1) { | |
Write-Host "Duplicate GUID: $($group.Name) (Count: $($group.Count))" -ForegroundColor Red | |
$foundDuplicates = $true | |
} | |
} | |
# If there were none, output that instead! | |
if (-not $foundDuplicates) { | |
Write-Host "No duplicate GUIDs were found." | |
} |
You can then use grep
or similar tools to find the files or folders that have the duplicate GUIDs. For example, in a git repository you can run:
git grep --recurse-submodules cb3892a2411d7d74284ba952f374ca45 *.meta
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: