2007-01-22, 12:31 AM
I just thought I'd share this in case anyone wants to use it.
Over the course of time I had many hundreds of .edl files (from ShowAnalyzer or Comskip) and some .txt files for which the .mpg records had long ago been deleted. As well, there were hundreds of <ShowName> folders in the
\Recordings folder which were empty of files except for the leftover .edl files.
So I wrote a small Windows Powershell script to delete all such files for which there isn't a similarly-named .mpg file, and then delete all the subsequently empty folders. (If you haven't tried it, Powershell is free from Microsoft and HUGELY better than DOS batch.) Then I set up a Windows scheduled task to automatically run Powershell, invoked with the script, once a month in the middle of the night.
Here is the script if you want it:
[SIZE="2"][COLOR="Green"]# location of GBPVR Recordings directory
$Root = "F:\GBPVR Recordings"
$Folders = $Root + "\*"
$Files = $Folders + "\*"
#function to change the extension of a path&file name
function ChangeExt {
param([string] $file, [string] $OldExt, [string] $NewExt)
return [Regex]::Replace($file, $OldExt+"$", $NewExt, [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
}
# remove all files (except Folder.jpg) for which there isn't a similarly-named .mpg file
dir $Files -Exclude *.mpg, Folder.mpg | where {-not (Test-Path (ChangeExt $_.FullName $_.Extension ".mpg")) } | Remove-Item
#Find and delete all empty \Recordings\<ShowName> directories
dir $Folders | where {$_.PSIsContainer} | where {-not (test-path ($_.FullName+"\*"))} | Remove-Item[/COLOR][/SIZE]
Over the course of time I had many hundreds of .edl files (from ShowAnalyzer or Comskip) and some .txt files for which the .mpg records had long ago been deleted. As well, there were hundreds of <ShowName> folders in the
\Recordings folder which were empty of files except for the leftover .edl files.
So I wrote a small Windows Powershell script to delete all such files for which there isn't a similarly-named .mpg file, and then delete all the subsequently empty folders. (If you haven't tried it, Powershell is free from Microsoft and HUGELY better than DOS batch.) Then I set up a Windows scheduled task to automatically run Powershell, invoked with the script, once a month in the middle of the night.
Here is the script if you want it:
[SIZE="2"][COLOR="Green"]# location of GBPVR Recordings directory
$Root = "F:\GBPVR Recordings"
$Folders = $Root + "\*"
$Files = $Folders + "\*"
#function to change the extension of a path&file name
function ChangeExt {
param([string] $file, [string] $OldExt, [string] $NewExt)
return [Regex]::Replace($file, $OldExt+"$", $NewExt, [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
}
# remove all files (except Folder.jpg) for which there isn't a similarly-named .mpg file
dir $Files -Exclude *.mpg, Folder.mpg | where {-not (Test-Path (ChangeExt $_.FullName $_.Extension ".mpg")) } | Remove-Item
#Find and delete all empty \Recordings\<ShowName> directories
dir $Folders | where {$_.PSIsContainer} | where {-not (test-path ($_.FullName+"\*"))} | Remove-Item[/COLOR][/SIZE]