Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: glob a folder of images, and open text doc, find the matches and move the images.

by flieckster (Scribe)
on Feb 10, 2020 at 01:54 UTC ( #11112710=note: print w/replies, xml ) Need Help??


in reply to Re: glob a folder of images, and open text doc, find the matches and move the images.
in thread glob a folder of images, and open text doc, find the matches and move the images.

Hi thanks for the info. the info in the 'dropback.txt' is as follows.
/Volumes/photorepos/Partners/Christopher_Banks/post/CB_instock/4/01001 +1510005801_0669_main.psd /Volumes/photorepos/Partners/Christopher_Banks/post/CB_instock/4/01001 +1520006618_5030_main.psd /Volumes/photorepos/Partners/Christopher_Banks/post/CB_instock/4/01001 +1520006812_0670_main.psd /Volumes/photorepos/Partners/Christopher_Banks/post/CB_instock/9/01001 +1510005801_0964_main.psd /Volumes/photorepos/Partners/Christopher_Banks/post/CB_instock/9/01001 +1520006618_0964_main.psd /Volumes/photorepos/Partners/Christopher_Banks/post/CB_instock/9/01001 +1520006812_0990_main.psd
the output of your code is simlar to what i saw:
010011510005801_0669_main.psd and /Volumes/photorepos/Partners/Christo +pher_Banks/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 010011510005801_0964_main.psd and /Volumes/photorepos/Partners/Christo +pher_Banks/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 010011520006618_0964_main.psd and /Volumes/photorepos/Partners/Christo +pher_Banks/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 010011520006618_5030_main.psd and /Volumes/photorepos/Partners/Christo +pher_Banks/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 010011520006812_0670_main.psd and /Volumes/photorepos/Partners/Christo +pher_Banks/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 010011520006812_0990_main.psd and /Volumes/photorepos/Partners/Christo +pher_Banks/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 010011520006816_3034_main.psd and /Volumes/photorepos/Partners/Christo +pher_Banks/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 010011520007257_0126_main.psd and /Volumes/photorepos/Partners/Christo +pher_Banks/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 010011520007259_5031_main.psd and /Volumes/photorepos/Partners/Christo +pher_Banks/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 010013000007469_4036_alternate1.psd and /Volumes/photorepos/Partners/C +hristopher/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 010013000007469_4036_main.psd and /Volumes/photorepos/Partners/Christo +pher_Banks/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 010013000007471_0990_alternate1.psd and /Volumes/photorepos/Partners/C +hristopher/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 010013000007471_0990_main.psd and /Volumes/photorepos/Partners/Christo +pher_Banks/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 080080520009970_0155_main.psd and /Volumes/photorepos/Partners/Christo +pher_Banks/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd 080081510009702_0001_alternate1.psd and /Volumes/photorepos/Partners/C +hristopher/Volumes/photorepos/Partners/Christopher_Banks/post/CB_inst +ock/4/010011520006618/Volumes/photorepos/Partners/Christopher_Banks/p +ost/CB_instock/4/010011520006812/Volumes/photorepos/Partners/Christop +her_Banks/post/CB_instock/9/010011510005801/Volumes/photorepos/Partne +rs/Christopher_Banks/post/CB_instock/9/010011520006618/Volumes/photor +epos/Partners/Christopher_Banks/post/CB_instock/9/010011520006812_099 +0_main.psd
are you saying that i need to use /\Q$row/because of the paths?
  • Comment on Re^2: glob a folder of images, and open text doc, find the matches and move the images.
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: glob a folder of images, and open text doc, find the matches and move the images.
by haukex (Bishop) on Feb 10, 2020 at 10:01 UTC
    the output of your code is simlar to what i saw:

    That's unlikely, since my code doesn't contain any prints. Not even your original code contains the word and that's showing up in this output. And I really don't see which code would cause the pathname to apparently be repeated six times in what appears to be the same string. Use Data::Dumper or Data::Dump for debug output like I suggested and post the actual code you're running, and maybe we'll have a chance to help. See How do I post a question effectively? and I know what I mean. Why don't you? in addition to Short, Self-Contained, Correct Example.

    are you saying that i need to use /\Q$row/because of the paths?

    Not quite, the \Q escapes metacharacters in $row that would otherwise be interpreted as regex characters. Anyway, that's not the only suggestion I made, what about the others?

      This is the full code image using. i added print for yours to see what it was doing, since it doesn't seem to find a match.
      #!/usr/bin/env perl -w use File::Find; use File::Copy; use File::Basename; use File::Basename; use File::Slurp; use POSIX qw(strftime); my $date = strftime("%m-%d-%y",localtime); my $time = strftime("%I:%M:%S",localtime); my $findme = "/Volumes/photorepos/Perl/SLAperlDropback/"; my $file_loc = $findme. '2SLAday'; my $filenames_to_putback = '/Volumes/photorepos/Perl/SLAperlDropback/d +ropback.txt'; chdir($file_loc) or warn "$!"; @filesforeach = glob "*.*"; my $filecount = @filesforeach; print "$filecount\n"; chomp @filesforeach; foreach $file (@filesforeach){ print "$file\n"; open(my $fh, "<", "$filenames_to_putback") or warn "$!\n"; while (my $row = <$fh>) { chomp $row; print "$row\n"; my @line = $file; for (@line) { if ($_ =~ /$row/) { chomp $_; push @output, "found $_ that matched redo $file $row <br>"; move($_,$row) or warn "shit went wrong yo! $!\n"; } } } } print "@output\n";
      i added an else statment to your code with a print out.
      #!/usr/bin/env perl use warnings; use strict; use File::Copy 'move'; my $findme = '/Volumes/photorepos/Perl/SLAperlDropback/'; chdir($findme.'2SLAday') or die "chdir: $!"; foreach my $file (glob "*.*") { open my $fh, '<', $findme.'dropback.txt' or die "open: $!"; while ( my $row = <$fh> ) { chomp $row; if ( $file =~ /$row/ ) { print "$file\n"; print "$row\n"; move( $file, $row ) or die "move: $!"; } else { print "$file has no match $!\n"; } } }
      output had not match
      010011510005801_0669_main.psd has no match 010011510005801_0964_main.psd has no match 010011520006618_0964_main.psd has no match 010011520006618_5030_main.psd has no match 010011520006812_0670_main.psd has no match 010011520006812_0990_main.psd has no match 010011520006816_3034_main.psd has no match 010011520007257_0126_main.psd has no match 010011520007259_5031_main.psd has no match 010013000007469_4036_alternate1.psd has no match 010013000007469_4036_main.psd has no match 010013000007471_0990_alternate1.psd has no match 010013000007471_0990_main.psd has no match 080080520009970_0155_main.psd has no match 080081510009702_0001_alternate1.psd has no match
      i'm guessing that there is no movement because it won't find a match due to the paths are being interpreted as regex when it comes to the filenames in each row.
        i'm guessing that there is no movement because it won't find a match due to the paths are being interpreted as regex when it comes to the filenames in each row.

        It doesn't look like you took any of my suggestions so far.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11112710]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2022-05-28 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?