#!/bin/bash

# Sets the file modification time to that of the timestamp in the filename
# for the file(s) specified, or, if none are specified, for all files 
# that start with 'cr_data_' and end in either '.json' or '.txt'

if [ $# -ge 1 ] ; then

	for f in "$@" ; do
		echo "Adjusting time of $f"
		touch -t `echo $f | sed 's/[^0-9]*\([0-9]*\)\([0-9][0-9]\)\..*/\1.\2/'` $f
	done

else

	for f in cr_data_*.json cr_data_*.txt ; do 
		echo "Adjusting time of $f"
		touch -t `echo $f | sed 's/[^0-9]*\([0-9]*\)\([0-9][0-9]\)\..*/\1.\2/'` $f
	done

fi

