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.
> 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
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
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'