<?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 Re: check to see if multiple files exist in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/check-to-see-if-multiple-files-exist/m-p/3842073#M97912</link>
    <description>Hi Rahul:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;my @arr = glob "/path/file*";&lt;BR /&gt;unlink for (@arr);&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Fri, 11 Aug 2006 14:31:11 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2006-08-11T14:31:11Z</dc:date>
    <item>
      <title>check to see if multiple files exist</title>
      <link>https://community.hpe.com/t5/operating-system-linux/check-to-see-if-multiple-files-exist/m-p/3842070#M97909</link>
      <description>I have written a perl script in which I need to check if files exist in a directory and then remove them from that directory.&lt;BR /&gt;&lt;BR /&gt;I am doing the following:&lt;BR /&gt;&lt;BR /&gt;my @arr = `ls \directory\file*`;&lt;BR /&gt;&lt;BR /&gt;my $arr_cnt = $#arr +1;&lt;BR /&gt;&lt;BR /&gt;if ($arr_cnt &amp;gt; 0)&lt;BR /&gt;{&lt;BR /&gt;        foreach (@arr)&lt;BR /&gt;        {&lt;BR /&gt;                unlink($_);&lt;BR /&gt;        }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This works fine if there are files in the directory but retuns an error message that no file exist in that directory if that directory does not have files of the specified pattern.&lt;BR /&gt;&lt;BR /&gt;I know that I cannot check if multiple files exist with the file test.&lt;BR /&gt;&lt;BR /&gt;Can anyone help.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Rahul</description>
      <pubDate>Fri, 11 Aug 2006 14:16:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/check-to-see-if-multiple-files-exist/m-p/3842070#M97909</guid>
      <dc:creator>Rahul_13</dc:creator>
      <dc:date>2006-08-11T14:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: check to see if multiple files exist</title>
      <link>https://community.hpe.com/t5/operating-system-linux/check-to-see-if-multiple-files-exist/m-p/3842071#M97910</link>
      <description>seems like overkill for perl to me but &lt;BR /&gt;&lt;BR /&gt;if (scalar(@arr) &amp;gt; 1) { do something }&lt;BR /&gt;&lt;BR /&gt;that should tell you if you have multiple items in your array.</description>
      <pubDate>Fri, 11 Aug 2006 14:29:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/check-to-see-if-multiple-files-exist/m-p/3842071#M97910</guid>
      <dc:creator>Marvin Strong</dc:creator>
      <dc:date>2006-08-11T14:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: check to see if multiple files exist</title>
      <link>https://community.hpe.com/t5/operating-system-linux/check-to-see-if-multiple-files-exist/m-p/3842072#M97911</link>
      <description>You just need to redirect stderr of your ls.&lt;BR /&gt;&lt;BR /&gt;my @arr = `ls \directory\file*`;&lt;BR /&gt;becomes:&lt;BR /&gt;my @arr = `ls \directory\file* 2&amp;gt;/dev/null`;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Aug 2006 14:30:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/check-to-see-if-multiple-files-exist/m-p/3842072#M97911</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-08-11T14:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: check to see if multiple files exist</title>
      <link>https://community.hpe.com/t5/operating-system-linux/check-to-see-if-multiple-files-exist/m-p/3842073#M97912</link>
      <description>Hi Rahul:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;my @arr = glob "/path/file*";&lt;BR /&gt;unlink for (@arr);&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 11 Aug 2006 14:31:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/check-to-see-if-multiple-files-exist/m-p/3842073#M97912</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-08-11T14:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: check to see if multiple files exist</title>
      <link>https://community.hpe.com/t5/operating-system-linux/check-to-see-if-multiple-files-exist/m-p/3842074#M97913</link>
      <description>Hi Rahul:&lt;BR /&gt;&lt;BR /&gt;The 'glob' is a Perl built-in, so it's faster than invoking an external 'ls'.&lt;BR /&gt;&lt;BR /&gt;That aside, there is no need to test for the number of array elements --- the 'foreach' (or shorter 'for') iterates over the array (or list) until there are no more elements.  If there are none to begin with, the loop terminates immediately.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 11 Aug 2006 14:38:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/check-to-see-if-multiple-files-exist/m-p/3842074#M97913</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-08-11T14:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: check to see if multiple files exist</title>
      <link>https://community.hpe.com/t5/operating-system-linux/check-to-see-if-multiple-files-exist/m-p/3842075#M97914</link>
      <description>Hi Rahul:&lt;BR /&gt;&lt;BR /&gt;Actually, we can eliminate iterating over the list; pass it in it's entirely to 'unlink'; count the number of files removed; and print that summary in one short piece of code.  For example:&lt;BR /&gt;&lt;BR /&gt;# perl -e '$n=unlink glob("/tmp/*.log");printf "%d file%s unlinked\n", $n, $n==1 ? "":"s"'&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 11 Aug 2006 16:54:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/check-to-see-if-multiple-files-exist/m-p/3842075#M97914</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-08-11T16:54:50Z</dc:date>
    </item>
  </channel>
</rss>

