Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Check if unicode directory exists

by paddycoep (Initiate)
on Aug 06, 2012 at 08:06 UTC ( #985627=perlquestion: print w/replies, xml ) Need Help??
paddycoep has asked for the wisdom of the Perl Monks concerning the following question:

I am checking if the Unicode directory exists using -d check and if Exists then copying the files in the unicode directory using System DOS COPY command. The Unicode directory name is taken from STDIN. But though the Directory exists, it active perl shows false for -d check. If instead of taking the unicode directory name from STDIN, if I hard core the name in the perl script then it works. How Can I take the unicode directory name from STDIN which I can check if Exists using -d and then can COPY the files in this directory. I am using Active Perl 5.14

Replies are listed 'Best First'.
Re: Check if unicode directory exists
by moritz (Cardinal) on Aug 06, 2012 at 08:17 UTC
Re: Check if unicode directory exists
by Anonymous Monk on Aug 06, 2012 at 08:50 UTC

      The wordy approach

      use Fcntl q' :mode '; use Win32::Unicode::Native; use Data::Dump; my $filename = shift; my @f = my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($filename); dd \@f, S_ISDIR( $mode ), S_ISREG($mode);

      Less wordy

      #!/usr/bin/perl -- use strict; use warnings; use Data::Dump; use File::stat(); use Win32::Unicode::Native; # stat is statW, open is openW, ... for my $filename ( @ARGV ){ my $stat_obj = File::stat::populate( stat( $filename ) ); dd $filename, $stat_obj, { isdir => -d $stat_obj, isfile => -f $st +at_obj }; } __END__ $ perl win32.unicode.stat.utf8.pl . win32.unicode.stat.utf8.pl ( ".", bless([3, 0, 16895, 1, 0, 0, 3, 0, 1344244307, 1344244307, 115650180 +3, "", ""], "File::stat"), { isdir => 1, isfile => "" }, ) ( "win32.unicode.stat.utf8.pl", bless([3, 0, 33206, 1, 0, 0, 3, 444, 1344244390, 1344244390, 1344244 +307, "", ""], "File::stat"), { isdir => "", isfile => 1 }, )

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://985627]
Approved by moritz
help
Chatterbox?
[tye]: 1) The python stack traces show you the names of variables, not the values of variables. Almost never informative.
[LanX]: do you have a py job now?
[tye]: Right now I have errors trying to fetch stuff from graphite. It says 'apps not ready, check startup logs'. I eventually find the startup logs and see 'no apps found'. Looking for fixes to this problem...
[LanX]: no idea ... ask py monks! ;-p
[tye]: it turns out that this can be caused by almost anything going wrong. If you want to know what caused the problem, you have to try to load each app by-hand to see what problems it is having, because none of those will be logged.
[tye]: No, I write more Perl than py at work. But I have to deal with plenty of py things.
[tye]: py monks would just be offended.
[Corion]: ;)
[Corion]: Hi tye btw ;)
[Corion]: I found plenty of not chatty enough logs with Perl too ... I'm slowly coming to appreciate Log::Log4perl resp. our homegrown alternative

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-09-21 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (252 votes). Check out past polls.

    Notices?