# Check if directory is empty

**URL:** https://discourse.chef.io/t/check-if-directory-is-empty/13065
**Category:** Chef Infra (archive)
**Created:** [May 14, 2018, 4:48pm UTC](https://discourse.chef.io/t/check-if-directory-is-empty/13065 "2018-05-14T16:48:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![coul](https://avatars.discourse-cdn.com/v4/letter/c/b19c9b/32.png) [@coul](https://discourse.chef.io/u/coul)
#### Post date: [May 14, 2018, 4:48pm UTC](https://discourse.chef.io/t/check-if-directory-is-empty/13065/1 "2018-05-14T16:48:21Z")

</div>

I have Ubuntu 16.04 with chef-client 14.1.1.  
I have two steps with contrary conditions but both are run (spoiler: that folder is empty)

```auto
docker_container "build_packages" do
....
  only_if { ::Dir.empty?('/opt/chef/deb/') }
end

bash 'publish new deb package' do
....  
  not_if { ::Dir.empty?('/opt/chef/deb/') }
end

```

Why is it happening?

---

<div class="post-metadata">

### Author: ![raghureddy45](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@raghureddy45](https://discourse.chef.io/u/raghureddy45)
#### Post date: [May 15, 2018, 3:40pm UTC](https://discourse.chef.io/t/check-if-directory-is-empty/13065/2 "2018-05-15T15:40:00Z")

</div>

you can do like this

```auto
not_if { Dir["/opt/chef/deb/*"].empty? }

```

---

<div class="post-metadata">

### Author: ![coul](https://avatars.discourse-cdn.com/v4/letter/c/b19c9b/32.png) [@coul](https://discourse.chef.io/u/coul)
#### Post date: [May 22, 2018, 11:46am UTC](https://discourse.chef.io/t/check-if-directory-is-empty/13065/3 "2018-05-22T11:46:38Z")

</div>

It doesn’t work as well.  
I made a test. I removed bash block and there was nothing in `/opt/chef/deb/` folder after first step. So there is nothing at folder and `not_if` isn’t catching it.
