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

···

--
Posted via http://www.ruby-forum.com/.

Quoting Peter Bailey (lists@ruby-forum.com):

  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

···

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

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)

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

···

--
Posted via http://www.ruby-forum.com/.

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

···

Date: Thu, 29 Nov 2012 22:39:52 +0900
From: lists@ruby-forum.com
Subject: removing directories
To: ruby-talk@ruby-lang.org

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

--
Posted via http://www.ruby-forum.com/\.

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

···

Date: Thu, 29 Nov 2012 22:39:52 +0900
From: lists@ruby-forum.com
Subject: removing directories
To: ruby-talk@ruby-lang.org

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

--
Posted via http://www.ruby-forum.com/\.

Great stuff. Thank you very much.

···

--
Posted via http://www.ruby-forum.com/.

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.

···

--
Posted via http://www.ruby-forum.com/\.