maphew

Match file timestamps

Developed while working on PHA SVG Assembly, making timestamps of input files match output files. 

It could be generalized for wider utility. Took me about an hour to figure out. It would have been faster but I spent time trying to generalize. In the end I gave up because the structure of the rest of the script has too much hard coded contextual info. A lesson for me to spend more time encapsulating and not just building one thing on another in an evergrowing pile.

def match_timestamp(inMapDir, outDir): 
	'''Set the output svg & png files to match time stamp of the input maps 

	in map: elk-pha-active.svg 
	out : Elk.svg, Elk.png 
	''' 
	species = 'Caribou,Elk,Goat,Moose,Sheep'.split(',') 
	for s in species: 
		fname = os.path.join(inMapDir, s.lower() + '-pha-active.svg') 
		# T:\ENV.474\script\Maps\elk-pha-active.svg 
		mtime = os.path.getmtime(fname) 
		atime = os.path.getatime(fname) 
	for f in glob.glob("{}/{}.*".format(outDir, s)): 
		# T:\ENV.474\script\Output\2020-03-20\Elk.svg, Elk.png 
		os.utime(f, (atime, mtime)) 
	return