if the directory already exists, then why the need to overwrite it?
here''s a little module i use
lib/myfileutils.rb
module MyFileUtils
# method: MyFileUtils.mkdir
# params: directory path as string, ex: /some/path
# returns: true - created directory, false = directory exists, nil - could
not create directory
def self.mkdir(dir)
begin
return false if File.directory?(dir) # directory already exists
return true if Dir.mkdir(dir) # successfully created directory
rescue SystemCallError => e
return nil # can''t create the directory (most likely permissions
problem)
end
end
end
require ''myfileutils''
do_something unless MyFileUtils.mkdir("/some/path").nil?
On 6/13/06, Darkwax <DArk1254@yahoo.com> wrote:>
> Hi, I have a quick question. I am trying to create folders dinamically
> using FileUtils.mkdir, the problem is that if the folder already exist
> it gives me an error. Does anyone know if there are any options to mkdir
> that would let me overwrite the already existing directory? I just need
> to create a folder with the same name everytime. Any other solution you
> might suggest? Thanks.
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060614/2440e449/attachment.html