Ark De appel
2007-Jan-27  22:23 UTC
is it possible to check on extension and delete a file?
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?
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederic Oehl
2007-Jun-01  12:22 UTC
Re: is it possible to check on extension and delete a file?
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... Did you try something like FileUtils.rm Dir.glob(''*.so'')? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---