In a previous post, Delete Files in subfolders after encode, I got a working script, I confirmed it deleted one file in a test folder I created, but in my normal folders the script (as standalone as well as implemented in my main script) fails to delete the files while giving an error message like this: "Missing permissions...; You don't have the permissions and so on" when running the scripts as admin I get the same error. What can I do to fix this?
The Script I got:
Get-ChildItem *.mkv | where BaseName -notlike '*`[HEVC]' | foreach {
# Convert the input file and send ffmpeg's output to the display,
# by piping to Write-Host, rather than trough the pipeline.
ffmpeg -i $_ -c:v libx265 -c:a copy -x265-params crf=25 "$($_.BaseName) [HEVC].mkv" -n |
Write-Host
# Conversion OK? Output the file-info object, which pipes it to Remove-Item.
if ($LASTEXITCODE -eq 0) { $_ }
} | Remove-Item
My script for all folders:
$current_path = Get-Location
$directories = get-childitem -path $current_path -Recurse -Directory
Foreach ($dir in $directories) {
Set-Location $dir.fullname
& "G:\Folder1\Compressing ps1 and bat\ffmpeg powershell HEVC.ps1"
}