Reputation: 16236
It appears that perl will not accept a UNC path filename. Does anyone know of a workaround?
I tried both UNC and URL forms. Escaping the backslashes produces the same result as using just single backslashes.
13:35:39.28 C:\test\t
C:> perl -v | head -2 -
This is perl, v5.10.0 built for MSWin32-x86-multi-thread
13:35:40.43 C:\test\t
C:> type ft.pl
#!/usr/bin/local/perl
use Time::localtime;
$mtime=(stat("ft.pl"))[9];
$t=localtime($mtime);
print sprintf("%04d-%02d-%02d %02d:%02d:%02d\n", $t->year + 1900, $t->mon + 1, $t->mday, $t->hour, $t->min, $t->sec);
$mtime=(stat("\\\\zzz047922\\c$\\test\\t\\ft.pl"))[9];
$t=localtime($mtime);
print sprintf("%04d-%02d-%02d %02d:%02d:%02d\n", $t->year + 1900, $t->mon + 1, $t->mday, $t->hour, $t->min, $t->sec);
$mtime=(stat("//zzz047922//c$/test/t/ft.pl"))[9];
$t=localtime($mtime);
print sprintf("%04d-%02d-%02d %02d:%02d:%02d\n", $t->year + 1900, $t->mon + 1, $t->mday, $t->hour, $t->min, $t->sec);
13:35:50.62 C:\test\t
C:> perl ft.pl
2014-03-18 13:29:35
1969-12-31 17:00:00
1969-12-31 17:00:00
Many thanks, ikegami. I should have done that, but I was fixing a one-liner and did not think about it. Here is the resulting script.
M:> type getfiletimestamp.bat
@echo off
SETLOCAL
SET EXITCODE=0
IF "%1" == "" (ECHO usage: %0 ^<filename^> & SET EXITCODE=1 & GOTO TheEnd)
IF NOT EXIST "%1" (ECHO file "%1" does not exist & SET EXITCODE=2 & GOTO TheEnd)
SET FT=%~f1
SET F=%FT:\=/%
SET F=%F:$=\$%
perl -e "{use Time::localtime; $mtime=(stat(\"%F%\"))[9]; $t=localtime($mtime); print sprintf("%%04d-%%02d-%%02d %%02d:%%02d:%%02d\", $t->year + 1900
, $t->mon + 1, $t->mday, $t->hour, $t->min, $t->sec );}"
:TheEnd
EXIT /B %EXITCODE%
Upvotes: 0
Views: 710
Reputation: 385764
Always use use strict; use warnings;
!
>type x.pl
use strict;
use warnings;
print "\\\\zzz047922\\c$\\test\\t\\ft.pl", "\n";
>perl x.pl
Use of uninitialized value $\ in concatenation (.) or string at x.pl line 3.
\\zzz047922\c est\t\ft.pl
Now go escape the $
or switch to single quotes.
Upvotes: 2