Skip to content

Instantly share code, notes, and snippets.

@1RedOne
Last active May 25, 2016 17:49
Show Gist options
  • Select an option

  • Save 1RedOne/c1d4c90db3e04c251963e4a44248d20e to your computer and use it in GitHub Desktop.

Select an option

Save 1RedOne/c1d4c90db3e04c251963e4a44248d20e to your computer and use it in GitHub Desktop.
Find files longer than 260 chars
$files = New-Object System.Collections.ArrayList
$length = 100
$folder = 'J:\SLC\Anderson v. Gold Coast\Experts'
Function Show-FolderPickerDialog{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$dialog = new-object System.Windows.Forms.FolderBrowserDialog
[void]$dialog.ShowDialog()
$dialog.SelectedPath
}
Function Show-PromptForChoice {
$title = "Copy Files"
$message = "Do you want to copy these files into another directory??"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Copies the files to the destination chosen."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Retains all the files in the folder."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
$result
}
write-output " Listing files longer than $length chars..."
dir -Recurse -Path $folder | Where-Object {$_.FullName.Length -ge $length } | ForEach-Object {
$parentFolder= $_.FullName.Split("\")[-3]
$childFolder = $_.FullName.Split("\")[-2]
$_.FullName
[void]$files.Add($_)
}
$choice = Show-PromptForChoice
switch ($choice) {
0 {
$destination = Show-FolderPickerDialog
Write-Output "Copying all files to $destination"
copy-item -path $files.FullName -Destination $destination -WhatIf
}
1 {
Write-Output "User chose not to copy files, exiting..."
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment