EDIT: nvm some information has been given to me about this and i will absolutely need a listfile with absolute filenames and paths of files that need to be copied. but you can however look over the code... and easily use it to compare two directories and get md5s and whatever. i was copying whole directories while preserving filepaths as well :) but if you feel like you know why it wasnt atleast copying from one path to the other please fill me in cz i would love to know haha

anyway sory to bother.

ok girls and biys here is the script. take it easy on me tho, im still green lol.

I am wanting to copy from the 455dex to 455cex OR from 455dex to a temp folder. the main purpose of this script is to scan the cex directory and copy the dex files to it if they are different. .... i say again :) copy from 455dex to 455cex and based on difference in structure.
use strict; use warnings; use diagnostics; use File::Copy::Recursive qw(fcopy rcopy); use File::Path qw(make_path remove_tree); use Digest::MD5; use Time::HiRes qw( time ); my $start = time(); my $dir1 = $ARGV[0]; my $dir2 = $ARGV[1]; if ( not defined $dir1 ) { print "\nUsage: rexscan.pl [folder]\n"; exit(0); } elsif ( not defined $dir2 ) { $dir2 = ''; } remove_tree( "CEX", "DEX" ); my @first_arg = (); my @second_arg = (); my @dex_md5_array = (); my @cex_md5_array = (); my $countera = 0; my $counterb = 0; first_arg($dir1); second_arg($dir2); get_files(); sub first_arg { my ($dir) = @_; my ($dh); if ( !opendir( $dh, $dir ) ) { return; } while ( my $file = readdir($dh) ) { next if ( -d $file ); my $path = "$dir/$file"; if ( -d $path ) { first_arg("$path"); } else { push( @first_arg, "$dir/$file" ); } } } sub second_arg { my ($dir) = @_; my ($dh); if ( !opendir( $dh, $dir ) ) { return; } while ( my $file = readdir($dh) ) { next if ( -d $file ); my $path = "$dir/$file"; if ( -d $path ) { second_arg("$path"); } else { push( @second_arg, "$dir/$file" ); } } } sub get_files { for my $element1 (@first_arg) { next if ( -d $element1 ); $element1 =~ m#^(.*?)([^/]*)$#; my ( $dex_directory, $dex_temp_file) = ( $1, $2 ); my $dex = "$dex_directory$dex_temp_file"; open (my $dex_file, '<', $dex)|| die "line 90 $!"; my $dex_md5 = Digest::MD5->new->addfile($dex_file)->hexdigest; + push @dex_md5_array, "$dex_md5 $dex_directory $dex_temp_file\n +"; } for my $element2 (@second_arg) { next if -d $element2; $element2 =~ m#^(.*?)([^/]*)$#; my ( $cex_directory, $cex_temp_file ) = ( $1, $2 ); my $cex = "$cex_directory$cex_temp_file"; open (my $cex_file, '<', $cex) || die "line 101"; my $cex_md5 = Digest::MD5->new->addfile($cex_file)->hexdigest; push @cex_md5_array, "$cex_md5 $cex_directory $cex_temp_file"; } for my $cex_md5_array (@cex_md5_array) { my ( $md5c, $cpath, $cfile ) = split /\s+/, ($cex_md5_array); + #cex md5 filepath and file stored here chomp ( $md5c, $cpath, $cfile ); for my $dex_md5_array (@dex_md5_array) { my ( $md5d, $dpath, $dfile ) = split (/\s+/,$dex_md5_array +); #dex md5 filepath and file stored here chomp ( $md5d, $dpath, $dfile ); if ($md5c ne $md5d && $cfile eq $dfile){ make_path("DEX"); fcopy("$dpath$dfile", "DEX/$cpath"); #or use this to copy directly to the other directory. #fcopy("$dpath$dfile", "$cpath"); } else { print ''; } } } } my $end_run = time(); my $end = time(); my $runtime = sprintf( "%.5f", $end - $start ); print "This script took $runtime seconds to execute\n";
and i am wanting to copy from the 455dex directory to the 455cex directory OR copy the DEX directory to a temp folder while preserving cex filepath <.<
i dont see why it cant be accomplished as a simple file copy process, and why it has to be so hard for me, but what started off as a simple project turned into a pretty hefty task. hopefully someone sees something i dont.


In reply to Re: File copy based on conditions in two arrays by james28909
in thread File copy based on conditions in two arrays by james28909

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.