in reply to Re^4: dir handle
in thread dir handle

Well, since we don't know what your system (OS) is, nor have your full code, that's an issue on which it's hard for us to offer any help.

"doesn't work" is detail-free... but details are exactly what we need to do any better than WAG'ing.

But for a pair of WAGs, are you sure Path::Tiny installed correctly? ...that you have the latest version?


Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
  1. code
  2. verbatim error and/or warning messages
  3. a coherent explanation of what "doesn't work actually means.

check Ln42!

Replies are listed 'Best First'.
Re^6: dir handle
by Mjpaddy (Acolyte) on May 27, 2014 at 11:58 UTC

    system : windows 7

    i search for file::tiny in ppm but not found

    my logic:

    open both dir and take list of filename in array so one contain 2 and other 3 then in for loop i run index of array to capture individual file and apply copy() from File::Copy but when i m using $test1$x one dir contain one less file so i got an err so my copy statement not executed.. please help....
    use strict; use warnings; use File::Copy; my @test1; my @test2; print "Enter the file path form where you want to copy file:\n"; chomp(my $path1 = <STDIN>); opendir DH, "$path1" || die "$!"; @test1 = readdir (DH); print "@test1\n"; print "Enter the file path form where you want to copy file:\n"; chomp(my $path2 = <STDIN>); opendir DH, "$path2" || die "$!"; @test2 = readdir (DH); print "@test2\n"; my $count = @test1; my $count2 = @test2; my $x = 0; for ($x = 0; $x<$count2; $x++) { if($test1[$x] ne $test2[$x]) { print "$test1[$x] : $test2[$x]\n"; # copy("$test1[$x]", "$path2") or warn "cannot copy $test1[$x]" +; # copy("$test2[$x]", "$path1")or warn "cannot copy $test2[$x]"; +; } }

      If you just want a list of the files in a directory then it's easier to just use glob

      Also note that the files in a directory are not ordered, so any list will be in a random order unless you sort it.

      Your code could then look something like this :-

      use File::Basename; my @files = glob('/path/to/files/*'); foreach my $file (@files) { my $name = basename($file); if (! -x "/new_path/$name") { # copy file here } }

      Have a look at the help for File::Basename or better yet File::Spec for functions to safely handle paths & filenames

      "i search for file::tiny in ppm but not found"

      That's not exactly surprising. In the prior discussion Anonymonk and choroba both mentioned Path::Tiny; you said you were trying to use File::Copy. PPM doesn't know about "file::tiny" because -- if it exists -- it's not on CPAN, or any other standard source.


      Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
      1. code
      2. verbatim error and/or warning messages
      3. a coherent explanation of what "doesn't work actually means.

      check Ln42!