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
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.
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
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