# Trying to delete file using FileUtils not working

**URL:** <https://www.ruby-forum.com/t/trying-to-delete-file-using-fileutils-not-working/144636>\
**Category:** Rails\
**Created:** [July 31, 2008, 5:48pm UTC](https://www.ruby-forum.com/t/trying-to-delete-file-using-fileutils-not-working/144636 "2008-07-31T17:48:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubylicious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/91b2a8/32.png) [@rubylicious](https://www.ruby-forum.com/u/rubylicious)\
**Post date:** [July 31, 2008, 5:48pm UTC](https://www.ruby-forum.com/t/trying-to-delete-file-using-fileutils-not-working/144636/1 "2008-07-31T17:48:25Z")

</div>

I have a directory (dir\_menu) that contains the following files:  
dir\_menu  
|-menu.htm  
|-menu\_lesson.htmt  
|-menu\_topic.htmt  
|-launchunitvars.js

I’m trying to remove the two files with the “.htmt” extensions using the  
following line of code:

Dir.foreach(“dir\_menu”) {|f| FileUtils.rm(f) if(f.include? “.htmt”)}

I keep getting the following error:

Errno::ENOENT (No such file or directory - menu\_lesson.htmt):

Obviously it finds the file otherwise it wouldn’t list the filename in  
the error message. What am I missing here?

---

<div class="post-metadata">

**Author:** ![rubylicious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/91b2a8/32.png) [@rubylicious](https://www.ruby-forum.com/u/rubylicious)\
**Post date:** [July 31, 2008, 6:07pm UTC](https://www.ruby-forum.com/t/trying-to-delete-file-using-fileutils-not-working/144636/2 "2008-07-31T18:07:59Z")

</div>

Nevermind. Figured it out. Need to take a different approach. Ended  
up doing the following for anyone else who wants to know.

Dir.chdir(“dir\_menu”)  
FileUtils.rm Dir.glob("\*.{htmt,jst}")
