user1694873
user1694873

Reputation: 473

Removing folder in Ruby under a path

I would like to be able to remove the folder "OLDFOLDER" and its sub folder in the following folder structure via a ruby script in linux (Im pretty new to ruby and Linux).

/X/Y/Z/OLDFOLDER/SUBFOLDERS

I know there are ways to remove folders in ruby, for example:

removeOldFolder = "rm /X/Y/Z/OLDFOLDER/"
    `#{removeOldFolder}`

but i am not sure how to remove folders like the structure i have above,

Any help much appreciated

Upvotes: 1

Views: 85

Answers (1)

tadman
tadman

Reputation: 211670

You should be using FileUtils rather than system calls to commands like this.

A better way of doing this:

FileUtils.rm_rf("/X/Y/Z/OLDFOLDER/")

Do be extremely careful when executing rm -rf on arbitrary locations.

Upvotes: 3

Related Questions