if (!-d $logsDir) {
print "LOGSDIR: [$logsDir] does not exist\n";
}
else {
print "LOGSDIR: [$logsDir] exists\n";
}
I am passing the following value to $logsDir
from command line and getting the following output
LOGSDIR: [c:\temp><] exists
I do have C:\temp
. I know temp><
is not a valid folder name on windows. But shouldn't -d
give me the correct answer saying that this directory does not exist?
thanks
Thanks for the edit and the answer. Here is the modified code and output, it still doesn't work.
use strict;
use warnings;
my $logsDir = $ARGV[0];
if (-d $logsDir) {
print "$logsDir exists";
} else {
print "$logsDir does not exist!";
}
__END__
Results
>perl test60.pl c:\temp
c:\temp exists
>perl test60.pl c:\temp^<^>
c:\temp<> exists
Thanks to melporne, I also tried this
C:\Users\XXXX>dir C:\temp
Volume in drive C is System
Volume Serial Number is XXXX
Directory of C:\temp
09/16/2019 12:07 AM <DIR> .
09/16/2019 12:07 AM <DIR> ..
07/03/2019 11:50 PM 765 abcd.txt
07/04/2019 12:24 AM 765 efgh.txt
07/04/2019 12:41 AM 765 efgh.txt
and so on
C:\Users\XXXX>dir C:\temp^<^>
Volume in drive C is System
Volume Serial Number is XXXX
Directory of C:\
09/16/2019 12:07 AM <DIR> Temp
09/15/2019 05:33 PM <DIR> temp1
11/19/2018 06:06 PM <DIR> Temp;
09/15/2019 12:31 AM <DIR> temparchive
0 File(s) 0 bytes
4 Dir(s) yyyyyyyyyyy bytes free
I do have the above folders, so it looks like it is treating it as temp*. The above result is exactly similar to this
C:\Users\XXXX>dir C:\temp*
Volume in drive C is System
Volume Serial Number is XXXX
Directory of C:\
09/16/2019 12:07 AM <DIR> Temp
09/15/2019 05:33 PM <DIR> temp1
11/19/2018 06:06 PM <DIR> Temp;
09/15/2019 12:31 AM <DIR> temparchive
0 File(s) 0 bytes
4 Dir(s) yyyyyyyyyyy bytes free