On Tue, 18 Apr 2006, Jack Coates wrote:
> I'm trying to get file creation or modification dates from a mapped
> network drive, using Win32 and Perl. Either of these methods works fine on
> local drives, but don't work on network drives:
>
> my $ctime=(stat($dir.$source))[10] or die "stat($dir\\$source) failed: $!\n";
>
> my $ctime = -M "$dir.$source"
>
> perldoc -f stat mentions that mtime isn't implemented on network shares,
> but says that the other functions should work; in fact, any stat() call
> fails with "file not found".
That seems wrong. Are you sure you specified your directory and file name
correctly. For example the sample code above looks inconsistent: If you
needed to include the \\ separator in the error message, you probably would
have needed it in the argument to the stat call too:
"$dir\\$source"
instead of
$dir.$source
and the ctime example is always wrong:
"$dir.$source"
because it embeds a literal dot.
> How can I get this done without switching languages? I'm almost desparate
> enough to `dir $dir.$source` and parse the results, which seems
> unspeakably lame.
Here is some sample code that uses Windows Scripting objects to determine the
modification date (and time) or a network file:
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Variant;
my $filename = '\\\\UNC_NAME\dir_name\file_name';
my $fso = Win32::OLE->new("Scripting.FileSystemObject");
my $file = $fso->GetFile($filename)
or die Win32::OLE->LastError;
print $file->DateLastModified;
The return value of $file->DateLastModified is a VT_DATE variant; check the
Win32::OLE::Variant documentation for different ways of formatting the
result.
Cheers,
-Jan
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs