Last active
July 27, 2020 04:51
-
-
Save samuel-fonseca/d3c81f471b654ed950c45b56a1de4914 to your computer and use it in GitHub Desktop.
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([string] $Path, [switch] $Recurse, [int] $Depth, [switch] $Force, [string] $Exclude, [switch] $Help) | |
if ($Help) { | |
Write-Output "This script is meant to delete all macOS dot files which serve no purpose on Windows." | |
Write-Output "When copying a large number of files, simply copy them onto the Windows machine, then run this script" | |
Write-Output "./removeMacOSDotFiles.ps1 | |
[[-Path] <string>] | |
[[-Depth] <int>] | |
[-Recurse] | |
[-Force] | |
[-Exclude]" | |
Write-Output "This script will automatically use the -Verbose option, which will output the logs of all deleted files." | |
exit | |
} | |
Write-Output "Initating macOS Dot Files Delete Script" | |
Write-Output "This script will delete all macOS dot_clean data files (.DS_Store and ._*) in '$Path'" | |
Write-Output "I am not responsible for what you do with this script. It is distributed as is and I offer no guarantee. Please, be careful how you use it." | |
# Confirm user wants to proceed with the script | |
do { | |
$userConfirm = (Read-Host 'Are you sure you want to proceed? This cannot be undone! (Y/N)').toLower() | |
} while ($userConfirm -notin @('y', 'n')) | |
if ($userConfirm -eq 'n') { | |
Write-Output "Process has been cancelled." | |
exit | |
} | |
if ([string]::isNullOrEmpty($path)) { | |
Write-Output "-Path has not been defined" | |
exit | |
} | |
$parameters = @{ | |
'Path' = $path | |
} | |
$parameters['Include'] = @(".DS_Store", "._*") | |
# $parameters['Exclude'] = '*' | |
# Conditional Params | |
if ($recurse) { $parameters['Recurse'] = $True } | |
if ($depth) { $parameters['Depth'] = $depth } | |
if ($force) { $parameters['Force'] = $True } | |
if ($exclude) { $parameters['Exclude'] = $True } | |
Write-Output "Getting ready to delete files..." | |
# Get all files and delete them | |
Get-ChildItem @parameters | | |
ForEach-Object { Remove-Item $_ -Force -Verbose } | | |
Measure-Object | |
# Process is completed | |
# This code will also output a total count of deleted objects | |
Write-Output "Files have been deleted. We're all done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment