# Is it possible to check on extension and delete a file?

**URL:** <https://www.ruby-forum.com/t/is-it-possible-to-check-on-extension-and-delete-a-file/83628>\
**Category:** Rails\
**Created:** [January 27, 2007, 11:23pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-check-on-extension-and-delete-a-file/83628 "2007-01-27T23:23:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/edb3f5/32.png) [@arkie](https://www.ruby-forum.com/u/arkie)\
**Post date:** [January 27, 2007, 11:23pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-check-on-extension-and-delete-a-file/83628/1 "2007-01-27T23:23:26Z")

</div>

Hi,

I have been struggling to write a ruby script that can detect if a file  
with a certain extension exists and to delete that file.

I have this:

require ‘find’  
total\_size = 0

Find.find(ENV[“HOME”]) do |path|  
if FileTest.directory?(path)  
if File.basename(path)[1] == ?.  
Find.prune # Don’t look any further into this directory.  
else  
next  
end  
else  
total\_size += FileTest.size(path)  
end  
end  
total\_size = total\_size / 1024  
print "Current home directory “,total\_size / 1024, " MB\n”,  
FileTest

it checks the home dir and reports how much space it takes but i also  
want to delete certain files. Is this possible? if so, can you give me  
an example so i can work it out?

---

<div class="post-metadata">

**Author:** ![arkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/edb3f5/32.png) [@arkie](https://www.ruby-forum.com/u/arkie)\
**Post date:** [June 1, 2007, 2:22pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-check-on-extension-and-delete-a-file/83628/2 "2007-06-01T14:22:57Z")

</div>

Ark De appel wrote:

> it checks the home dir and reports how much space it takes but i also  
> want to delete certain files. Is this possible? if so, can you give me  
> an example so i can work it out?

I was reading [http://www.ruby-doc.org/core/classes/FileUtils.html](http://www.ruby-doc.org/core/classes/FileUtils.html)…  
Did you try something like FileUtils.rm Dir.glob(‘\*.so’)?
