Removing directories

Hello,
I’ve googled around and I’ve discovered that "FileUtils.rm_rf(’#{dir}’)
will remove a directory. But, I can’t get it to work. I need to go into
a created subdirectory, move the files in there to the parent directory,
go back into the parent directory and remove the subdirectory. This is
all part of a graphic workflow I’m working on.

There is only one subdirectory created here, no more.

Dir.chdir(“T:/asura/ads_books/out/tiff”)
list = Dir.entries(’.’)
list.delete(".")
list.delete("…")

list.each do |dir|
Dir.chdir(“T:/asura/ads_books/out/tiff/#{dir}”)
Dir.glob("*.tiff").each do |tifffile|
FileUtils.mv(tifffile, “T:/asura/ads_books/out/tiff”)
end
Dir.chdir(“T:/asura/ads_books/out/tiff”)
FileUtils.rm_rf(’#{dir}’)
end

Thank you,
Peter

Subject: removing directories
Date: Thu 29 Nov 12 10:39:52PM +0900

Quoting Peter B. ([email protected]):

FileUtils.rm_rf(’#{dir}’)

When strings are included in single quotes, #{} expansion does not
take place. Try with

FileUtils.rm_rf("#{dir}")

(even if here, you already have a string, so

FileUtils.rm_rf(dir)

should equally do the trick)

Carlo

Thanks, Carlo. I actually figured this out myself, googling around. I
used double quotes instead of singles, and, I put the full path in there
in front of my directory variable.

Thanks again,
Peter

require ‘fileUtils’

And now the code to delete the directory tree.

FileUtils.remove_dir(“C:/Users/your/filepath/to_directory”)

To can read this lesson 27 @
http://www.oldkingjames.org/RUBY_LESSONS/ruby_lessons_index.html

Take a look at a lesson on oldkingjames.org FilUtils is used to delete
directory even with files inside.

Alex Mcmillan wrote in post #1087317:

require ‘fileUtils’

And now the code to delete the directory tree.

FileUtils.remove_dir(“C:/Users/your/filepath/to_directory”)

To can read this lesson 27 @
http://www.oldkingjames.org/RUBY_LESSONS/ruby_lessons_index.html

Beautiful! Thank you.

Great stuff. Thank you very much.