Skip to content

Instantly share code, notes, and snippets.

@haltcase
Last active May 16, 2023 15:10
Show Gist options
  • Save haltcase/0b2f0e1bdf7bbd09a1b488395d8c7023 to your computer and use it in GitHub Desktop.
Save haltcase/0b2f0e1bdf7bbd09a1b488395d8c7023 to your computer and use it in GitHub Desktop.
Find & delete leftover "dot underscore" files from macOS, using PowerShell on Windows.
# log the -WhatIf output to a file for review
start-transcript c:\mac-file-cleanup.txt
get-childitem -directory |
get-childitem -filter ._* -file -force -recurse |
# filter out the items that don't have an accompanying non-dot-underscore file
where-object { test-path -literalPath (join-path $_.directoryName ($_.name -replace '^\._','')) } |
foreach-object { remove-item -literalPath $_.fullName -force -WhatIf }
stop-transcript
get-childitem -directory |
get-childitem -filter ._* -file -force -recurse |
# filter out the items that don't have an accompanying non-dot-underscore file
where-object { test-path -literalPath (join-path $_.directoryName ($_.name -replace '^\._','')) } |
foreach-object { remove-item -literalPath $_.fullName -force }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment