<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Perl Script filter &amp;amp; copy file in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/perl-script-filter-amp-copy-file/m-p/3817385#M100203</link>
    <description>Hi,&lt;BR /&gt;I need to write a Perl script that takes a directory name as its argument, creates a new sub-directory called executables within it, then scans the directory and all its sub-directories looking for executables and moves them into the new sub-directory. &lt;BR /&gt;&lt;BR /&gt;I tried the below so far it create folder but could not filter &amp;amp; copy...&lt;BR /&gt;&lt;BR /&gt;use File::Copy;&lt;BR /&gt;print "Enter the directory name in which you need to check for files\n";&lt;BR /&gt;chomp(my $dir = &lt;STDIN&gt;);&lt;BR /&gt;&lt;BR /&gt;chdir $dir or die "Can't chdir to '$dir': $!"; &lt;BR /&gt;&lt;BR /&gt;opendir $dir,"." or die "Can't opendir '$dir': $!";&lt;BR /&gt;foreach (readdir $dir) &lt;BR /&gt;{&lt;BR /&gt;    next if $_ =~ /^\./;&lt;BR /&gt;    if($_ != 'executable')&lt;BR /&gt;     {&lt;BR /&gt;       mkdir "executable", 0755 or warn "Cannot make executable directory: $!";&lt;BR /&gt;       if (-x $_){&lt;BR /&gt;       copy("$_", "executable") or die "Can't copy '$_' to 'executable': $!\n"  and print "copied $_ into executable file\n";}&lt;BR /&gt;     }&lt;BR /&gt;    if($_ != 'graphics')&lt;BR /&gt;     {&lt;BR /&gt;      mkdir "graphics" or warn "Cannot make graphics directory: $!";&lt;BR /&gt;      if($_ == "*.jpg")&lt;BR /&gt;      {&lt;BR /&gt;        copy("$_", "graphics") or die "Can't copy '$_' to 'graphics': $!\n" and print "copied $_ into graphics file\n";&lt;BR /&gt;      }&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;closedir $dir;&lt;BR /&gt;&lt;BR /&gt;&lt;/STDIN&gt;</description>
    <pubDate>Wed, 05 Jul 2006 01:53:22 GMT</pubDate>
    <dc:creator>Sasirekha</dc:creator>
    <dc:date>2006-07-05T01:53:22Z</dc:date>
    <item>
      <title>Perl Script filter &amp; copy file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-script-filter-amp-copy-file/m-p/3817385#M100203</link>
      <description>Hi,&lt;BR /&gt;I need to write a Perl script that takes a directory name as its argument, creates a new sub-directory called executables within it, then scans the directory and all its sub-directories looking for executables and moves them into the new sub-directory. &lt;BR /&gt;&lt;BR /&gt;I tried the below so far it create folder but could not filter &amp;amp; copy...&lt;BR /&gt;&lt;BR /&gt;use File::Copy;&lt;BR /&gt;print "Enter the directory name in which you need to check for files\n";&lt;BR /&gt;chomp(my $dir = &lt;STDIN&gt;);&lt;BR /&gt;&lt;BR /&gt;chdir $dir or die "Can't chdir to '$dir': $!"; &lt;BR /&gt;&lt;BR /&gt;opendir $dir,"." or die "Can't opendir '$dir': $!";&lt;BR /&gt;foreach (readdir $dir) &lt;BR /&gt;{&lt;BR /&gt;    next if $_ =~ /^\./;&lt;BR /&gt;    if($_ != 'executable')&lt;BR /&gt;     {&lt;BR /&gt;       mkdir "executable", 0755 or warn "Cannot make executable directory: $!";&lt;BR /&gt;       if (-x $_){&lt;BR /&gt;       copy("$_", "executable") or die "Can't copy '$_' to 'executable': $!\n"  and print "copied $_ into executable file\n";}&lt;BR /&gt;     }&lt;BR /&gt;    if($_ != 'graphics')&lt;BR /&gt;     {&lt;BR /&gt;      mkdir "graphics" or warn "Cannot make graphics directory: $!";&lt;BR /&gt;      if($_ == "*.jpg")&lt;BR /&gt;      {&lt;BR /&gt;        copy("$_", "graphics") or die "Can't copy '$_' to 'graphics': $!\n" and print "copied $_ into graphics file\n";&lt;BR /&gt;      }&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;closedir $dir;&lt;BR /&gt;&lt;BR /&gt;&lt;/STDIN&gt;</description>
      <pubDate>Wed, 05 Jul 2006 01:53:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-script-filter-amp-copy-file/m-p/3817385#M100203</guid>
      <dc:creator>Sasirekha</dc:creator>
      <dc:date>2006-07-05T01:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Perl Script filter &amp; copy file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-script-filter-amp-copy-file/m-p/3817386#M100204</link>
      <description>&lt;!--!*#--&gt;1. Use File::Find ?&lt;BR /&gt;2. Use ne/eq instead of ==/!= if comparing strings&lt;BR /&gt;3. Use patterm matches instead of !+ "*.jpg"&lt;BR /&gt;&lt;BR /&gt;This recurses into subfolders with File::Find, and fixes all your errors. Take from it what you need&lt;BR /&gt;&lt;BR /&gt;--8&amp;lt;---&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;&lt;BR /&gt;use File::Find;&lt;BR /&gt;use File::Copy;&lt;BR /&gt;&lt;BR /&gt;print "Enter the directory name in which you need to check for files\n";&lt;BR /&gt;chomp (my $dir = &lt;STDIN&gt;);&lt;BR /&gt;&lt;BR /&gt;chdir $dir or die "Can't chdir to '$dir': $!\n";&lt;BR /&gt;&lt;BR /&gt;find (sub {&lt;BR /&gt;    m/^\./ and return;&lt;BR /&gt;    if ($_ ne 'executable') { # Here was your error. != is numeric comparison&lt;BR /&gt;        mkdir "executable", 0755 or warn "Cannot make executable directory: $!";&lt;BR /&gt;        if (-x $_) {&lt;BR /&gt;            # Specify full target here, and do not double-quote $_: n ot needed&lt;BR /&gt;            copy ($_, "executable/$_") or die "Can't copy '$_' to 'executable': $!\n";&lt;BR /&gt;            print "copied $_ into executable file\n";&lt;BR /&gt;            }&lt;BR /&gt;        }&lt;BR /&gt;    if ($_ ne "graphics") { # != vs ne again&lt;BR /&gt;        mkdir "graphics" or warn "Cannot make graphics directory: $!";&lt;BR /&gt;        if (m/\.jpg$/) { # $_ == "*.jpg" is unexplainable wrong. Not numeric, and no patter match&lt;BR /&gt;            copy ($_, "graphics/$_") or die "Can't copy '$_' to 'graphics': $!\n";&lt;BR /&gt;            print "copied $_ into graphics file\n";&lt;BR /&gt;            }&lt;BR /&gt;        }&lt;BR /&gt;    }, $dir);&lt;BR /&gt;--&amp;gt;8---&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn&lt;/STDIN&gt;</description>
      <pubDate>Wed, 05 Jul 2006 02:06:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-script-filter-amp-copy-file/m-p/3817386#M100204</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-07-05T02:06:53Z</dc:date>
    </item>
  </channel>
</rss>

