Forum: Ruby folder delete script

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E9fe98d2276bd1c259dc9b99c1f7ca97?d=identicon&s=25 Gus Hoppes (Guest)
on 2007-04-02 19:51
(Received via mailing list)
Hi. I am a rubyn00b. I need help. I'm trying to write a script that will
delete specific sub folders in a particular folder. I would like to
delete
all folders that begin with lets say the letter "T" that are two weeks
old.
It would probably work like the deltree command in dos (deltree T*.*
/s).
How would I write that in ruby? Is it also possible to use wildcards in
ruby? If so how? Any help would be greatly appreciated. TY!
4d5b5dd4e263d780a5dfe7ac8b8ac98c?d=identicon&s=25 Tim Pease (Guest)
on 2007-04-02 20:10
(Received via mailing list)
On 4/2/07, Gus Hoppes <gushoppes@gmail.com> wrote:
> Hi. I am a rubyn00b. I need help. I'm trying to write a script that will
> delete specific sub folders in a particular folder. I would like to delete
> all folders that begin with lets say the letter "T" that are two weeks old.
> It would probably work like the deltree command in dos (deltree T*.* /s).
> How would I write that in ruby? Is it also possible to use wildcards in
> ruby? If so how? Any help would be greatly appreciated. TY!
>

The Dir.glob command will help you find folders that start with a
particular letter.  The File.stat command will help you determine the
creation / modification times of those folders and whether or not they
are folders at all.

The documentation for these items can be found on the Ruby-doc website.

http://www.ruby-doc.org/core/

Have fun learning Ruby!  Ruby has taught me more about programming
than any other language out there. The community is simply wonderful,
too.

Blessings,
TwP
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2007-04-02 20:18
(Received via mailing list)
On Tue, 3 Apr 2007, Gus Hoppes wrote:

> Hi. I am a rubyn00b. I need help. I'm trying to write a script that will
> delete specific sub folders in a particular folder. I would like to delete
> all folders that begin with lets say the letter "T" that are two weeks old.
> It would probably work like the deltree command in dos (deltree T*.* /s).
> How would I write that in ruby? Is it also possible to use wildcards in
> ruby? If so how? Any help would be greatly appreciated. TY!
>

harp:~ > cat a.rb
require 'fileutils'

pattern = 'T*.*'

Dir.glob('**/**') do |entry|
   next unless test ?d, entry
   FileUtils.rm_rf entry if File.fnmatch pattern, entry
end


-a
This topic is locked and can not be replied to.