I'm finally close to get it working. However I run this code but it doesnt copy any files. It doesn't give me any errors. Could anybody look at my code to see if I'm missing anything or need to change my code???
Basically the code reads a file an grabs an array of directory paths, then I use File::Find recursevily to go over each one of those path to copy a "word1.rtf" file to a new directory call "C:\testfiles"
I really need help ...I've been working on this for two weeks without success. Now, I could change my code to copy only one file and it stops. But I want to be able to go to every single directory and grab its RTF file. I know that I'm close ..please help!!
#! perl
use strict;
use File::Copy;
use File::Find;
no warnings 'File::Find';
my $infile = "c:\\doclist1.chr";
my @directories;
# first lets build our directory list
open IN, "<$infile" or die "Couldn't open $infile, $!";
while (<IN>) {
chomp;
my @fields = split /,/;
my $path_str = $fields[6];
do { warn "Empty field 7"; next } unless $path_str;
my @path = split /\\/, $path_str;
# push the directories into an array
push @directories, join "\\", @path[ 0, 5, 6 ];
}
close IN;
exit;
# now we have a directory list in @directories let's process it
# for my $dir ( @directories ) {
# process_directories($dir);
#}
sub process_directories {
if (/\.rtf$/) {
push @directories, $File::Find::name;
copy($File::Find::name, "C:\\testfiles\\$_") or die "Failed to cop
+y $_: $!\n";
}
}
find(\&process_directories, $File::Find::dir);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.