Problem while changing file's modification time using utime() on windows

Discussion in 'Perl Misc' started by Sudeep George, Oct 19, 2004.

  1. Hi

    I have implemented a perl script to 'touch' all files in a directory
    using utime().
    The implementation is working fine, but due to limitations of utime()
    on Windows, utime() will not modify the attributes of a file if it is
    opened or read-only.
    I am using Active State Perl v5.8.4 on a Windows 2000 machine.

    There is an existing perl module Win32API::File::Time which addresses
    this specific problem. But this perl module is not installed by
    default[atleast by Active State]. I would like the people using this
    script, to avoid installing a perl module inorder to run the same.

    I used Win32::File [GetAttribute , SetAttribute] to handle the
    read-only issue. This is working fine.

    Any ideas how to handle the case when the file being 'touch'ed is
    opened already?

    TIA,
    Sudeep George.
    Sudeep George, Oct 19, 2004
    #1
    1. Advertising

  2. Sudeep George

    Jon Ericson Guest

    Re: Problem while changing file's modification time using utime()on windows

    (Sudeep George) writes:

    > I have implemented a perl script to 'touch' all files in a directory
    > using utime(). The implementation is working fine, but due to
    > limitations of utime() on Windows, utime() will not modify the
    > attributes of a file if it is opened or read-only. I am using
    > Active State Perl v5.8.4 on a Windows 2000 machine.
    >
    > There is an existing perl module Win32API::File::Time which
    > addresses this specific problem. But this perl module is not
    > installed by default[atleast by Active State]. I would like the
    > people using this script, to avoid installing a perl module inorder
    > to run the same.


    It is possible to test at runtime whether or not a module is
    available. Something like:

    eval { require Win32API::File::Time };
    my $use_api = $@ ? 0 : 1;

    > I used Win32::File [GetAttribute , SetAttribute] to handle the
    > read-only issue. This is working fine.


    Some touch implementations support a -f option to attempt to touch a
    file that does not have the needed permissions. I notice that the
    Solaris and GNU implimentations update files that are owned by the
    user regardless of permissions.

    > Any ideas how to handle the case when the file being 'touch'ed is
    > opened already?


    Print an error message? If the user doesn't have Win32API::File::Time
    installed, this would be an ideal time to suggest it.

    Jon
    Jon Ericson, Oct 19, 2004
    #2
    1. Advertising

  3. Sudeep George

    Ben Morrow Guest

    Quoth (Sudeep George):
    > I have implemented a perl script to 'touch' all files in a directory
    > using utime().
    > The implementation is working fine, but due to limitations of utime()
    > on Windows, utime() will not modify the attributes of a file if it is
    > opened or read-only.
    > I am using Active State Perl v5.8.4 on a Windows 2000 machine.
    >
    > There is an existing perl module Win32API::File::Time which addresses
    > this specific problem. But this perl module is not installed by
    > default[atleast by Active State]. I would like the people using this
    > script, to avoid installing a perl module inorder to run the same.


    Try PAR.
    Or, if WIN32API::File::Time is pure perl, copy it into a BEGIN block at
    the top of your script and add an import after, like

    BEGIN {
    # stuff from WIN32API::File::Time
    }
    Win32API::File::Time->import(qw/what you would have put after use
    Win32API::File::Time/);

    > I used Win32::File [GetAttribute , SetAttribute] to handle the
    > read-only issue. This is working fine.
    >
    > Any ideas how to handle the case when the file being 'touch'ed is
    > opened already?


    This is not a Perl question, it is a Win32 question. The answer will the
    same for a program written in any other language that runs on Win32.

    Ben

    --
    If you put all the prophets, | You'd have so much more reason
    Mystics and saints | Than ever was born
    In one room together, | Out of all of the conflicts of time.
    The Levellers, 'Believers'
    Ben Morrow, Oct 19, 2004
    #3
  4. Jon Ericson <> wrote in message
    > > Any ideas how to handle the case when the file being 'touch'ed is
    > > opened already?

    >
    > Print an error message? If the user doesn't have Win32API::File::Time
    > installed, this would be an ideal time to suggest it.


    Looks like there is no other way other than including the module for
    my functionality. I was hoping for some dirty work-around, but all
    approaches to this issue on Windows point to the method implemented in
    Win32API::File::Time.

    Thanks,
    Sudeep
    > Jon
    Sudeep George, Oct 20, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Bless
    Replies:
    1
    Views:
    2,844
    Matt Gerrans
    Dec 9, 2004
  2. mike
    Replies:
    2
    Views:
    229
  3. Matt Scilipoti
    Replies:
    2
    Views:
    185
    Matt Scilipoti
    Jun 6, 2007
  4. Matt Spendlove

    utime a dir and convert Date to Time

    Matt Spendlove, Jan 15, 2008, in forum: Ruby
    Replies:
    3
    Views:
    102
    Siep Korteling
    Jan 15, 2008
  5. zswu
    Replies:
    2
    Views:
    98
Loading...

Share This Page