boat73 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to run the following code on Winxp machine. From what I am seeing in the docs it should work but doesn't.
use File::Xcopy; my $obj = File::Xcopy->new; # copy all the files with .txt extension if they exists in /tgt/dir $obj->xcopy('c:/TEMP', 'c:/temp2', '\.txt$');
The output is as follows. I don't see what I have wrong so any help is greatly appreciated. Thanks in advance
# Xcopy Log Output
# Date: Thu Dec 16 12:15:52 2004
# Input parameters:
# From dir: /temp2
# To dir: /TEMP
# File Pat: \.txt$
# Action : copy
# File statistics: category: count: pct: total size
# The Same size and time: 1: 20.00%: 0 Bytes
# Different size or time: 1: 20.00%: 0 Bytes
# File does not exist in FROM folder: : 0.00%:
# File is older or the same: : 0.00%: 0 Bytes
# File is newer and its size bigger: 1: 20.00%: 0 Bytes
# File is newer and its size smaller: : 0.00%:
# File does not exist in TO folder: 4: 80.00%: 568.454KB
# -----------------------------------: ---------:-------:----------
# Totals: 5:100.00%: 568.454KB
#
# File size: max 581694 min 0 diff 6D17:34:54
# File time: max 20041216.121230 min 19800101.000000 diff 9116D12:12:30
#
#action| from_time| to_time| tmdiff| from_size| to_size| szdiff|file_name
OW|20041216.121230|20041216.115402| 18:28| 0 Bytes| 0 Bytes| 0 Bytes|./.
no action|19800101.000000|19800101.000000| 00| 0 Bytes| 0 Bytes| 0 Bytes|./..
NA| |20041216.113115| | | 0 Bytes| |./File-Xcopy-0.11
NA| |20041124.065053| | | 568.061KB| |./Text.exe
NA| |20041124.065026| | | 14 Bytes| |./Text.txt
NA| |20041209.131530| | | 389 Bytes| |./test.pl

Replies are listed 'Best First'.
Re: File::Xcopy problem
by jimbojones (Friar) on Dec 16, 2004 at 21:01 UTC
    Based on what I see in the version I downloaded (File::Xcopy 0.11), this isn't ready for prime-time

    The pattern matching doesn't work

    The file copy seems to my eyes to be coded wrong. From Lines 362ff
    foreach my $f (sort keys %{$rr}) { ++$m; $tp = ${$rr}{$f}{type}; # skip if the file only exists in to_dir next if ($tp =~ /^OLD/); $f1 = "${$rr}{$f}{f_pdir}/$f"; $f1 = "${$rr}{$f}{t_pdir}/$f"; ########## Jimbojones comment -- note that $f2 is never set. # +###### if ($act =~ /^c/i) { # copy ++$n; copy $f1, $f2 if $tp =~ /^(NEW|EX1|EX2)/; } elsif ($act =~ /^m/i) { # move ++$n; copy $f1, $f2 if $tp =~ /^(NEW|EX1|EX2)/; move $f1; } elsif ($act =~ /^u/i) { # update ++$n; copy $f1, $f2 if $tp =~ /^(EX1|EX2)/; } elsif ($act =~ /^o/i) { # overwirte ++$n; copy $f1, $f2 if $tp =~ /^(EX0|EX1|EX2)/; } else { carp "WARN: $f - do not know what to do.\n"; } }
    The "to" file ($f2) is never set. Also, looking at the data dump of the $rr hash, the "to" directory "t_pdir" is empty if the file doesn't exist in the "to" directory. Hence you could never copy files that didn't already exist in the "to" directory.

    './Temp.txt' => HASH(0x22d1f6c) 'action' => 'CP' 'f_pdir' => 'C:/TEMP' 'f_size' => 0 'f_time' => 20041216.141033 'file' => 'Temp.txt' 'szdiff' => '' 't_pdir' => '' #-- Jimbojones comment. Null, should be 'C:/temp2' 't_size' => '' 't_time' => '' 'tmdiff' => '' 'type' => 'NEW'
    Unless you want to get into the guts of this thing, I'd look for another solution.

    - j

      Oh well, at least I know I am not crazy. Thanks to all
Re: File::Xcopy problem
by TStanley (Canon) on Dec 16, 2004 at 17:55 UTC
    After reading the POD, I'm guessing that the last line of your program should read:
    $obj->xcp('c:/temp','c:/temp2','\.txt$');

    Mind you this is a guess, as I haven't fully read the entire pod.

    TStanley
    --------
    The only thing necessary for the triumph of evil is for good men to do nothing -- Edmund Burke
      Tahnks, I had tried that as well as
      $obj->xcp('c:\\temp','c:\\temp2','\.txt$');
      but no good
        I believe that the problem is that you are looking for '\.txt$' files. Remembering that single quotes prevent interpolation, instead of looking for files that end in .txt, it is looking for files that end in .txt$ Try just '.txt'