Author |
Message |
bruce_s01
|
Posted: Fri Feb 24, 2012 8:42 am |
|
Joined: Tue Aug 08, 2006 7:08 pm
Posts: 561
Location:
UK
|
On finishing watching a file there appears to be a bit of activity from the system, if you delete the file before this stops, an orphaned ..mpg.png file is left. These files are not big, but they could build up over time so I wrote a short script to delete them: Code: #!/usr/bin/perl -s
if (defined ($ARGV[0])) { $CMDDIR = $ARGV[0] ; } else { $CMDDIR = "." ; }
print "DIR is:".$CMDDIR."\n";
if ( -d $CMDDIR ) { print "And it is a Directory \n"; chdir ($CMDDIR) ;
opendir(DIR, ".") or die "Can't open current directory $! \n"; print "Testing 1\n";
#find .mpg...png files in directory @pngnames = grep { /\.mpg.*png$/ } readdir(DIR) or die "No Target Files present:$!\n"; closedir(DIR);
foreach $pngname (@pngnames) { next if $pngname =~ /^\.\.?$/ ; # skip .. and .
#Shouldn't be any directory entries if (-d $name) { next; #can skip to the next name in the loop }
# create name of mpg from the png $mpgname = $pngname; $mpgname =~ s/\..*png$// ; $mpgname = $mpgname.".mpg" ;
#If the mpg does not exist, delete the png file if (!( -e $mpgname)) { print $pngname." Is an Orphan from ".$mpgname." \n"; print "Deleting... \n"; unlink ($pngname) ;
} } }
Just pass the directory path to the tv directory in the command line. It's not that intelligent, if no pathname is passed, it just uses the current directory, it doesn't do anything clever like looking up the db. Regards Bruce S.
_________________ Updated 2019/10/26: AthlonII X2 265 Gigabyte GA-970A-DS3P 16Gb PC 1866 DDR3, 500GB+2TB+4TB SATA HDD, SATA DVD-RW Asus DRW-24D5MT , NVIDIA GeForce GT1080 Hauppauage Nova-T 500, Nova-T LinHes R8.6.1
|
|
Top |
|
|
slowtolearn
|
Posted: Fri Feb 24, 2012 4:30 pm |
|
Joined: Wed Nov 16, 2005 8:55 pm
Posts: 1381
Location:
Farmington, MI USA
|
bruce_s01 wrote: On finishing watching a file there appears to be a bit of activity from the system, if you delete the file before this stops, an orphaned ..mpg.png file is left. These files are not big, but they could build up over time so I wrote a short script to delete them: Code: #!/usr/bin/perl -s
if (defined ($ARGV[0])) { $CMDDIR = $ARGV[0] ; } else { $CMDDIR = "." ; }
print "DIR is:".$CMDDIR."\n";
if ( -d $CMDDIR ) { print "And it is a Directory \n"; chdir ($CMDDIR) ;
opendir(DIR, ".") or die "Can't open current directory $! \n"; print "Testing 1\n";
#find .mpg...png files in directory @pngnames = grep { /\.mpg.*png$/ } readdir(DIR) or die "No Target Files present:$!\n"; closedir(DIR);
foreach $pngname (@pngnames) { next if $pngname =~ /^\.\.?$/ ; # skip .. and .
#Shouldn't be any directory entries if (-d $name) { next; #can skip to the next name in the loop }
# create name of mpg from the png $mpgname = $pngname; $mpgname =~ s/\..*png$// ; $mpgname = $mpgname.".mpg" ;
#If the mpg does not exist, delete the png file if (!( -e $mpgname)) { print $pngname." Is an Orphan from ".$mpgname." \n"; print "Deleting... \n"; unlink ($pngname) ;
} } }
Just pass the directory path to the tv directory in the command line. It's not that intelligent, if no pathname is passed, it just uses the current directory, it doesn't do anything clever like looking up the db. Regards Bruce S. Nice tip! A bash alternative (not trying to hijack, this is one of the things I love about Linux - "How can I skin this cat"!): Code: #!/bin/bash
for file in *.mpg.png do [ ! -f "${file%.*}" ] && { rm -f $file } done WARNING: Unlike Bruce's script this one has no intelligence, it will blindly remove any .mpg.png files that have no corresponding .mpg file in your current working directory.
|
|
Top |
|
|
tjc
|
Posted: Fri Feb 24, 2012 8:06 pm |
|
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location:
Arlington, MA
|
I remember a couple old scripts for doing this too. This old thread includes some examples, and someone (maybe brfransen?) wrote a fancy combined one that found files with no db entry and db entries with no file, that defaulted to safe "report only" mode and could be told to clean up... http://forum.linhes.org/viewtopic.php?f=6&t=6150
|
|
Top |
|
|
mattbatt
|
Posted: Fri Feb 24, 2012 9:05 pm |
|
Joined: Tue Aug 15, 2006 11:14 am
Posts: 1343
Location:
Orlando FL
|
If you remove a png file won't myth just make a new one when you scroll over it or play it?
_________________ My System
|
|
Top |
|
|
tjc
|
Posted: Sat Feb 25, 2012 11:12 am |
|
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location:
Arlington, MA
|
|
Top |
|
|
jams
|
Posted: Sat Feb 25, 2012 6:02 pm |
|
|
Site Admin |
Joined: Fri Jun 11, 2004 7:58 am
Posts: 507
|
you will find that a modified versino of find_orphans.py is already included.
|
|
Top |
|
|
tjc
|
Posted: Sun Feb 26, 2012 11:55 am |
|
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location:
Arlington, MA
|
Seems to be missing in 6.04, but that may just mean that I don't have some optional package installed.
|
|
Top |
|
|
jams
|
Posted: Sun Feb 26, 2012 12:16 pm |
|
|
Site Admin |
Joined: Fri Jun 11, 2004 7:58 am
Posts: 507
|
|
Top |
|
|
bruce_s01
|
Posted: Mon Jun 18, 2012 5:50 am |
|
Joined: Tue Aug 08, 2006 7:08 pm
Posts: 561
Location:
UK
|
Perhaps I should have looked a bit more closely.
_________________ Updated 2019/10/26: AthlonII X2 265 Gigabyte GA-970A-DS3P 16Gb PC 1866 DDR3, 500GB+2TB+4TB SATA HDD, SATA DVD-RW Asus DRW-24D5MT , NVIDIA GeForce GT1080 Hauppauage Nova-T 500, Nova-T LinHes R8.6.1
|
|
Top |
|
|