For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > October 2004 > Problem while changing file's modification time using utime() on windows









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

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

2004-10-19, 9:05 am

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

2004-10-20, 3:56 am

Jon Ericson <Jon.Ericson@jpl.nasa.gov> wrote in message
>
> 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

2004-10-20, 8:57 pm


Quoth sudeepgeorge@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.
ben@morrow.me.uk The Levellers, 'Believers'
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com