NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Information Community Announcements v
« Previous 1 … 24 25 26 27 28 … 56 Next »
cleanup \Recordings\<showname> folders

 
  • 0 Vote(s) - 0 Average
cleanup \Recordings\<showname> folders
BobAtTorrey
Offline

Member

Posts: 118
Threads: 49
Joined: Jul 2005
#1
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]
bckappen
Offline

Member

Posts: 51
Threads: 1
Joined: Jan 2006
#2
2007-01-22, 01:44 AM
BobAtTorrey,

Thanks for this handy script. Could you also post the instructions to make this run -- like what file extension (.ps1) to use and what command line to use in the scheduled task?

Thanks again for sharing this.
AMD Athlon64 2800+
1GB DDR and 2x 160GB SATA HDD
ATI Radeon X1650Pro AGP 8x 512MB DDR
1x OnAir HD, 2x HVR1600, 1x PVR-150
Cox Analog Cable and OTA ATSC
Windows XP SP3
GBPVR (>= 1.3.7)
BobAtTorrey
Offline

Member

Posts: 118
Threads: 49
Joined: Jul 2005
#3
2007-01-22, 04:11 AM
bckappen Wrote:BobAtTorrey,

Thanks for this handy script. Could you also post the instructions to make this run -- like what file extension (.ps1) to use and what command line to use in the scheduled task?

Thanks again for sharing this.

1. The easy question: Yes, Powershell scripts have a .ps1 extension.

2. Much trickier question: If the path to the script, or the script name, includes a space (e.g., "\Program files"), there's a real trick in writing the command line so Powershell won't be confused by the space(s) in the script path. So as an example here is my command line in the 'Run:' field of my Windows Scheduled Task:
[SIZE="2"]powershell.exe -Command "&'D:\My Documents\Computer\SOFTWARE I created\GBPVR utilities\GBPVR Recordings directory cleanup.ps1'"[/SIZE]

So that's the most general case. But if you have no spaces in the path and file name, you can remove most of the gibberish, eliminate the -Command switch, and that line can be as simple as:
[SIZE="2"]powershell c:\foo\x.ps1[/SIZE]

3. An added note: I was playing around and manually deleted a Folder.jpg (poster art for XRecord) in one of the folders. That created an anomalous situation in that the Thumbs.db (a hidden file created by Windows) remained, so the Remove-Item in the last line of the script, trying to delete that supposedly empty folder, failed. That was an artificially created situation, but if you might create such a situation and don't want that to stymie the script, then add a -force switch so the last Remove-Item becomes Remove-Item -force
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  NPVR Rename Recordings Batch File raceviper13 8 8,014 2011-04-23, 11:52 PM
Last Post: raceviper13
  Showname - Rename utility for GBPVR recordings Anthony 0 1,444 2009-03-05, 05:40 PM
Last Post: Anthony
  mTranscode BETA - automatic encoding of recordings jam_zhou 82 31,896 2008-10-21, 08:13 PM
Last Post: jam_zhou
  ComCut - Automatically clean recordings of commercials NiteShdw 154 56,603 2008-05-01, 02:14 PM
Last Post: missithang
  Video Podcasts of GBPVR Recordings fering 9 4,676 2008-03-16, 08:30 PM
Last Post: Grenlen
  Recordings2 - New Recordings Viewer psycik 25 7,258 2006-10-20, 12:11 AM
Last Post: psycik
  Recordings Viewer - version 2 psycik 18 4,862 2006-08-15, 07:48 AM
Last Post: mila06
  Manage conflicted recordings from the system tray Mister Slimm 0 1,049 2006-08-05, 08:25 PM
Last Post: Mister Slimm
  Manage reoccurring recordings from the system tray Mister Slimm 0 1,080 2006-08-04, 02:54 PM
Last Post: Mister Slimm
  Comskip 0.79 build 17: For recordings with insufficient black frames. erik 0 1,148 2006-01-21, 08:58 PM
Last Post: erik

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode