Forum: Ruby on Rails rake task ) fileutils how to remove parent specific folder

Posted by Kad Kerforn (kadoudal)
on 2012-11-20 12:09
(Received via mailing list)
I have a fixtures directory structure

fixtures
  en
    alpha
    beta
    delta
  es
    alpha
    beta
    delta

and one rake task to remove all fixtures

        path = File.join(MyApp.config.fixtures_path)
        FileUtils.rm_rf(path)

or all folders w specific locale
        path = File.join(MyApp.config.fixtures_path, locale)
        FileUtils.rm_rf(path)

but is there a way to remove all folders with name 'alpha'  in ALL 
locales
folder, and get a resulting structure

fixtures
  en
    beta
    delta
  es
    beta
    delta

thanks for your suggestions
Posted by Jordon Bedwell (Guest)
on 2012-11-20 12:20
(Received via mailing list)
On Tue, Nov 20, 2012 at 5:08 AM, Erwin <yves_dufour@mac.com> wrote:
>     delta
>
__SNIP__

> is there a way to remove all folders with name 'alpha'  in ALL locales
> folder, and get a resulting structure

FileUtils.rm_rf(Dir[Rails.root.join("spec/fixtures", "**/alpha")],
secure: true, force: true)
Posted by Jordon Bedwell (Guest)
on 2012-11-20 12:23
(Received via mailing list)
On Tue, Nov 20, 2012 at 5:18 AM, Jordon Bedwell <envygeeks@gmail.com> 
wrote:
>>     beta
>>     delta
>>
> __SNIP__
>
>> is there a way to remove all folders with name 'alpha'  in ALL locales
>> folder, and get a resulting structure
>
> FileUtils.rm_rf(Dir[Rails.root.join("spec/fixtures", "**/alpha")],
> secure: true, force: true)

Sorry ommit the force, I always forget that force is implied by rf
since I rarely use rf, so it should be
`FileUtils.rm_rf(Dir[Rails.root.join("spec/fixtures", "**/alpha")],
secure: true)`. I use r in production (and on development I trigger a
force but with constraints) because I like exceptions to be raised so
I know exactly what's going on in my filesystem but not all people
care about that
Posted by Kad Kerforn (kadoudal)
on 2012-11-20 12:38
(Received via mailing list)
Thanks Jordon
I also discover I can use Dir.glob  + match ... with directories .. (
though it was only for file

directories =
Dir.glob("#{File.join(MyApp.config.fixtures_path)}/*/\*alpha\*")

will test your answer too..  thanks again


Le mardi 20 novembre 2012 12:22:41 UTC+1, Jordon Bedwell a crit :
Posted by Kad Kerforn (kadoudal)
on 2012-11-20 12:47
(Received via mailing list)
Works great Jordon !  thanks again !!



Le mardi 20 novembre 2012 12:22:41 UTC+1, Jordon Bedwell a crit :
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.