Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

0 views
Skip to first unread message

Sudeep George

unread,
Oct 19, 2004, 8:24:00 AM10/19/04
to
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.

Jon Ericson

unread,
Oct 19, 2004, 1:34:21 PM10/19/04
to
sudeep...@gmail.com (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

Sudeep George

unread,
Oct 20, 2004, 1:53:47 AM10/20/04
to
Jon Ericson <Jon.E...@jpl.nasa.gov> 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

Ben Morrow

unread,
Oct 19, 2004, 1:43:09 PM10/19/04
to

Quoth sudeep...@gmail.com (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.
b...@morrow.me.uk The Levellers, 'Believers'

0 new messages