ironpaw has asked for the wisdom of the Perl Monks concerning the following question:

lo monks I have this script for reading a csv like so: c:\thisdir\thatone\somedoc.xls , 102324455 (unix date stamp) and taking those values and setting the last changed date on the file in question. I am using utime and it works IF i own the file (even though I have rights to the files). I understand this is a limitation of utime so fair enuff. Is there another tool/method of setting files back to their original time? here's my script (excuse my poor perl I am no monk yet).
use Win32::OLE; use File::stat; open(CSV, "c:/temp/doctime.txt"); #csv of filename , date @title = <CSV>; for ($i = 0; $i < scalar(@title); $i++) { ($file1[$i], $date[$i] $blank[$i]) = split(",", $title[$i]); } for ($a = 0; $a < scalar(@file1); $a++) { $access=$date[$a]; $filez = $file1[$a]; print "File name # $filez\n"; print "Previous date # $access\n"; utime $access, $access, $filez || die print "couldn not set utime for +$filez\n"; }
This works great loyally skipping any file not owned by me (which I don't want it to). I am running it from Win2k and the files are on Unix/Samba but the same thing happens locally. Any advice ideas would be great.

Replies are listed 'Best First'.
Re: setting time stamps on files
by castaway (Parson) on Jan 23, 2003 at 07:31 UTC
    I'm not exactly sure what you are looking for. However, the unix command 'touch' also does the same thing (and is available for Win in the cygwin gnu binaries..).
    Using touch on a file owned by root, to which I have write access (and write/executable access to the directory its in) works.
    It can take a parameter of the time you want to set (see the manpage) or even set it the same as another file.

    C.

      I was taking a look at getting touch working but no luck. Forgive my lack of knowledge but does what your saying mean i need to download a "plug in" for perl? cygwin gnu binaries? Thanks Pawz
        I didn't say anything about a plugin. I just meant with that, that if you need a 'touch.exe' for Windows, that there is one available. (Ask Google about the cygwin gnu binaries).

        Can you explain exactly what you are trying to do? I haven't understood it yet.
        Update the time on files:
        1. Not owned by you?
        2. In a directory you can't write to?
        3. Something else?

        C.