Update modify dates on parent folders using touch

Come up with a useful post-processing script? Share it here!
Post Reply
atmurray
Newbie
Newbie
Posts: 3
Joined: October 15th, 2009, 2:25 am

Update modify dates on parent folders using touch

Post by atmurray »

This script simply touches all folders in a path up to a specified parent folder.
Allows you to sort your TV folder by date so you know that a TV show has a new episode.

#!/bin/sh
# set TOPPATH to the top folder to "touch" to
# $1 is the path of the new download

TOPPATH="/data/downloads/complete/"

CURPATH=$1
while [ `expr "$CURPATH" : "$TOPPATH"` -gt 0 ]
do
#  echo "Touching $CURPATH"
  touch "$CURPATH"
  CURPATH=`dirname "$CURPATH"`
done
Sinnocence
Newbie
Newbie
Posts: 23
Joined: April 6th, 2009, 3:45 am

Re: Update modify dates on parent folders using touch

Post by Sinnocence »

Does anyone have a similar script for Windows (7)?

No matter what I try I can't seem to update the 'modified' date field, be it via unixutils, cygwin, powershell, etc.
Shady
Newbie
Newbie
Posts: 24
Joined: June 20th, 2009, 9:00 pm

Re: Update modify dates on parent folders using touch

Post by Shady »

Thanks man, i'l be adding this into a soon to be released postprocessing program in java: "postman" :)
I'l add support for windows 7 into it.
Sinnocence
Newbie
Newbie
Posts: 23
Joined: April 6th, 2009, 3:45 am

Re: Update modify dates on parent folders using touch

Post by Sinnocence »

Cheers Shady.

In the end I had to write a clunky script to create a temp file and remove it from each folder in the tree to force a timestamp update - I couldn't simply 'touch' the remote shares to bump their timestamps.
Shady
Newbie
Newbie
Posts: 24
Joined: June 20th, 2009, 9:00 pm

Re: Update modify dates on parent folders using touch

Post by Shady »

I gather from your reply that you mount your ntfs shares? if you do so under linux you could take a look at fstab. setting correct parameters may update timestamps automatically.
Sinnocence
Newbie
Newbie
Posts: 23
Joined: April 6th, 2009, 3:45 am

Re: Update modify dates on parent folders using touch

Post by Sinnocence »

Yes Shady - unfortunately the NAS I'm using (and soon replacing!) offers only minimal control over permissions. I can't even get a terminal window :(

Thanks for the help though!
konti
Newbie
Newbie
Posts: 5
Joined: December 14th, 2009, 4:32 am

Re: Update modify dates on parent folders using touch

Post by konti »

Hi sorry, but i don't understand the script. Whenever you download a episode it gets a newer timestamp right? So you'r episode are allways sorted? Could someone take the time to explain pls? thx.
Sinnocence
Newbie
Newbie
Posts: 23
Joined: April 6th, 2009, 3:45 am

Re: Update modify dates on parent folders using touch

Post by Sinnocence »

Hi Konti,

Supposing all your downloads are stored in /mnt/Files/Downloads, each with a subcategory, e.g. /mnt/Files/Downloads/TV Shows/. If you download the Pilot for a tv show called 'MyTvShow' this would look like /mnt/Files/Downloads/TV Shows/MyTvShow/MyTvShow - 1x01 - Pilot episode.avi

Normally when this file is created, the timestamp on the 'MyTvShow' folder would be updated to the current timestamp. This isn't necessarily true for 'TV Shows' or 'Downloads' which may keep their original timestamps. The OP's script allows you to specify that it should update ALL timestamps on ALL folders between the file, and the specified 'root' directory. Now, if you're browsing Downloads and sort by date, you would see that a new TV Show episode had been downloaded.
smiley5
Newbie
Newbie
Posts: 1
Joined: April 20th, 2011, 4:11 am

Re: Update modify dates on parent folders using touch

Post by smiley5 »

Does this also touch the file being downloaded? If not, how do I modify it to do that?
Thanks.
simzdk
Newbie
Newbie
Posts: 3
Joined: September 2nd, 2010, 6:36 am

Re: Update modify dates on parent folders using touch

Post by simzdk »

I wanted to try this script, but when i save it in my script folder, with extention .sh it dont show up. I have tried a test.py and that show up. Wrong extension?

UPDATE: Figured it out. Needed to run: chmod +x <file> on it.
Post Reply