<?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: Shell script: how to check whether a directory is empty? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-how-to-check-whether-a-directory-is-empty/m-p/2828958#M938170</link>
    <description>empty=$(ls -a | grep -v "." | &lt;BR /&gt;grep -v ".." | wc -l)&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;echo "Enter source directory: \c"&lt;BR /&gt;read dir1&lt;BR /&gt;echo "Enter destination directory: \c"&lt;BR /&gt;read dir2&lt;BR /&gt;pth=$PWD &lt;BR /&gt;cd $dir1&lt;BR /&gt;if [ $empty = "0" ]&lt;BR /&gt;  then&lt;BR /&gt;    echo "directory is empty"&lt;BR /&gt;else&lt;BR /&gt;   mv * "$pth"/"$dir2"&lt;BR /&gt;echo "Files transfered!"&lt;BR /&gt;fi</description>
    <pubDate>Fri, 18 Oct 2002 18:39:32 GMT</pubDate>
    <dc:creator>John Meissner</dc:creator>
    <dc:date>2002-10-18T18:39:32Z</dc:date>
    <item>
      <title>Shell script: how to check whether a directory is empty?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-how-to-check-whether-a-directory-is-empty/m-p/2828955#M938167</link>
      <description>I have a problem on creating a if statement as below. It is suppose to read the source directory and destination directory from the user, then move everything from the source to the destination. If the source is empty, it will stop to move files. How do I check whether a directory is empty?&lt;BR /&gt;--------------&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;echo "Enter source directory: \c"&lt;BR /&gt;read dir1&lt;BR /&gt;echo "Enter destination directory: \c"&lt;BR /&gt;read dir2&lt;BR /&gt;pth=$PWD&lt;BR /&gt;cd "$dir1"&lt;BR /&gt;if [ ??? ] #Problem: How to do the checking here?&lt;BR /&gt;then&lt;BR /&gt;   echo "no files in directory"&lt;BR /&gt;else&lt;BR /&gt;   mv * "$pth"/"$dir2"&lt;BR /&gt;   echo "Files transfered!"&lt;BR /&gt;fi&lt;BR /&gt;--------------&lt;BR /&gt;How do I do the checking of whether the directory is empty or not?&lt;BR /&gt;</description>
      <pubDate>Fri, 18 Oct 2002 14:21:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-how-to-check-whether-a-directory-is-empty/m-p/2828955#M938167</guid>
      <dc:creator>cybermilky</dc:creator>
      <dc:date>2002-10-18T14:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: how to check whether a directory is empty?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-how-to-check-whether-a-directory-is-empty/m-p/2828956#M938168</link>
      <description>How about something as trivial as:&lt;BR /&gt;&lt;BR /&gt;NFILES=$(ls ${dir1} | wc -l)&lt;BR /&gt;if [[ ${NFILES} -eq 0 ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "${dir1} is empty".&lt;BR /&gt;  fi&lt;BR /&gt;  &lt;BR /&gt;You might also add some checking to make sure that ${dir1} exists and is a directory.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 18 Oct 2002 14:26:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-how-to-check-whether-a-directory-is-empty/m-p/2828956#M938168</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-10-18T14:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: how to check whether a directory is empty?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-how-to-check-whether-a-directory-is-empty/m-p/2828957#M938169</link>
      <description>You might want to check for hidden files too, so change the ls to:&lt;BR /&gt;&lt;BR /&gt;ls -a ${dir1}| grep -v -e ^.$ -e ^..$ |wc -l&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin</description>
      <pubDate>Fri, 18 Oct 2002 14:34:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-how-to-check-whether-a-directory-is-empty/m-p/2828957#M938169</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2002-10-18T14:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: how to check whether a directory is empty?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-how-to-check-whether-a-directory-is-empty/m-p/2828958#M938170</link>
      <description>empty=$(ls -a | grep -v "." | &lt;BR /&gt;grep -v ".." | wc -l)&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;echo "Enter source directory: \c"&lt;BR /&gt;read dir1&lt;BR /&gt;echo "Enter destination directory: \c"&lt;BR /&gt;read dir2&lt;BR /&gt;pth=$PWD &lt;BR /&gt;cd $dir1&lt;BR /&gt;if [ $empty = "0" ]&lt;BR /&gt;  then&lt;BR /&gt;    echo "directory is empty"&lt;BR /&gt;else&lt;BR /&gt;   mv * "$pth"/"$dir2"&lt;BR /&gt;echo "Files transfered!"&lt;BR /&gt;fi</description>
      <pubDate>Fri, 18 Oct 2002 18:39:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-how-to-check-whether-a-directory-is-empty/m-p/2828958#M938170</guid>
      <dc:creator>John Meissner</dc:creator>
      <dc:date>2002-10-18T18:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: how to check whether a directory is empty?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-how-to-check-whether-a-directory-is-empty/m-p/2828959#M938171</link>
      <description>sorry the above post looks funny - i pasted from my term window and it wrapped lines... from the pipe on the first line just continue with what's on the second line....</description>
      <pubDate>Fri, 18 Oct 2002 18:40:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-how-to-check-whether-a-directory-is-empty/m-p/2828959#M938171</guid>
      <dc:creator>John Meissner</dc:creator>
      <dc:date>2002-10-18T18:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: how to check whether a directory is empty?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-how-to-check-whether-a-directory-is-empty/m-p/2828960#M938172</link>
      <description>Not to be the point police - but you'll get more responses in the future if you assign points to usefull replies you recieve here.</description>
      <pubDate>Tue, 22 Oct 2002 12:16:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-how-to-check-whether-a-directory-is-empty/m-p/2828960#M938172</guid>
      <dc:creator>John Meissner</dc:creator>
      <dc:date>2002-10-22T12:16:14Z</dc:date>
    </item>
  </channel>
</rss>

