need help on script to delete older sub-folder on qnap

Come up with a useful post-processing script? Share it here!

need help on script to delete older sub-folder on qnap

Postby chaleman » August 3rd, 2012, 5:34 pm

Hi Guys... this is an awesome place...

I have a QNAP 459Pro and I wish to write a post-processing script to delete the folder with the oldest date in a given subfolder. Reason is, I download David Letterman shows and only wish to keep, say the last 5... So my way of thinking (for keeping things simple) is to download the last 5 shows, and then when downloading the 6th one, implement the script... this way, after it finished downloading it, it should erase the oldest folder, thus always keeping just the last 5....

I tried this command:
rm -r $(ls -t -r /share/TV/David_Letterman | head -n 1)

The problem is that the sub-folders within the "David_Letterman" folder contain spaces.. i.e. "David Letterman 2012 07 26 Joel McHale HDTV x264 2HD" and this command can't deal with spaces when trying to delete them...

Can someone please shed some light on how to do this... This would be great!!! Thanks!

Carlos
chaleman
Newbie
Newbie
 
Posts: 1
Joined: August 3rd, 2012, 5:27 pm

Re: need help on script to delete older sub-folder on qnap

Postby shypike » August 5th, 2012, 3:37 am

Code: Select all
rm -r "$(ls -t -r /share/TV/David_Letterman | head -n 1)"
User avatar
shypike
Administrator
Administrator
 
Posts: 16724
Joined: January 18th, 2008, 1:49 pm


Return to Post-Processing Scripts