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

S

Sudeep George

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

Jon Ericson

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
 
B

Ben Morrow

Quoth (e-mail address removed) (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
 
S

Sudeep George

Jon Ericson said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top