Script sortof half-working?

I have directories full of files that contain dates and times in their names in the format YYYYMMDDhhmm. So like, one of the files is named 199407271609 with no file extension.

I have this script searches a given directory and changes all creation dates of the files to match the date in their name:

#! /bin/zsh

for filename in `ls $1`
do
touch -t $filename $1/$filename;
done

The script changes the creation dates correctly, but the only problem is, it's ignoring the hours and minutes part and making all the creation times 12:00 AM. What am I missing here? Any help greatly appreciated.

I'm not sure why you're getting the behavior you're seeing, but
the first thing I do when having trouble in a 'for' loop, is to
make sure the for variable has my expected result in it.

So if you do this:

for $filename in `ls $1`
do
  echo $filename
done

is $filename what you expect for all files? Is it preceded
with the directory information? That might make using it
as your time parameter for the -t in 'touch' rather difficult.

for filename in `ls $1`
do
touch -r  reference_file_name $1/$filename;
done

Is that what you mean? use a reference file for filetimes?

Since you didn't provide an example of output I will just take a stab at it.

The example you provide is dated from 1994 - any file that is modified over 6 months ago will show the year when doing an ls -l and not the time.

>ls -l 199407271609
-rw-r--r-- 1 jrr 0 Jul 27 1994 199407271609

>ls -l 199407271609
-rw-r--r-- 1 jrr 0 Feb 18 11:02 199407271609

Also, your system could have multiple versions of touch as mine does - /usr/bin/touch and /usr/ucb/touch both having their own personality.

John

Bingo! I'm an idiot, thanks for pointing that out. I was indeed looking at output that was saying 00:00 for the times. I tested this by creating a file like the one in my original example with a random date and time from like a month ago, and it shows up correctly.

Thanks everybody sorry!