Created
March 6, 2024 12:21
-
-
Save detain/a11f8dc0caabd91e4668e40a7ee40018 to your computer and use it in GitHub Desktop.
Restore the most recently deleted media file from recycling bin and add to PotPlayer playlist after the current position.
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
# Create a Shell COM object | |
$shell = New-Object -ComObject Shell.Application | |
# Get the Recycling Bin folder | |
$recycleBin = $shell.Namespace(0xa) | |
# Get the items in the Recycling Bin | |
$recycleBinItems = $recycleBin.Items() | |
# Sort items by deletion date in descending order | |
$sortedItems = $recycleBinItems | Sort-Object { $_.ExtendedProperty('System.Recycle.DateDeleted') } -Descending | |
$potPlayerDir = "C:\Program Files\DAUM\PotPlayer" | |
$potPlayerFull = "C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe" | |
# Get the most recently deleted item | |
$recycleBinItem = $sortedItems[0] | |
# Check if a file was found in the recycling bin | |
if ($recycleBinItem -ne $null) { | |
# Get the original path of the item before it was deleted | |
$originalPath = $recycleBinItem.ExtendedProperty('System.Recycle.DeletedFrom') | |
# Construct the full path to the restored file | |
$restoredFilePath = Join-Path $originalPath $recycleBinItem.Name | |
Write-Output "Restoring recycling bin $($restoredFilePath)" | |
# Restore the item from the recycling bin | |
$null = $recycleBinItem.InvokeVerb('undelete') | |
# Add the restored file to PotPlayer's playlist | |
# Extract the directory from the PotPlayer path | |
$null = Start-Process -FilePath $potPlayerFull -ArgumentList $originalPath, /insert -WorkingDirectory $potPlayerDir | |
} else { | |
Write-Output "No items found in the recycling bin." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment