Page 1 of 1

how to create a folder with Ruby

Posted: Thu Nov 07, 2013 8:38 pm
by jjs
Hi,

it's been a while.
But does anybody knows how to create a folder?

To get to a folder is easy but to create one?

For example a user puts in a name, then i want to create a folder in the My Documents folder.

I tried something like this:
begin
Dir::mkdir(directory_name)
rescue
puts "the directory already exists"
end

but....
anyone ?

thanks a lot for your help :)

Re: how to create a folder with Ruby

Posted: Thu Nov 07, 2013 8:49 pm
by jjs
found a solution that fits probably good enough

viewtopic.php?f=2&t=1354&p=5002&hilit=create+folder#p5002

thanks to Trog

Re: how to create a folder with Ruby

Posted: Sat Nov 09, 2013 9:07 am
by Tronic

Code: Select all

directory_name = "name"
Dir.mkdir(directory_name) unless File.exists?(directory_name)

Re: how to create a folder with Ruby

Posted: Sat Nov 09, 2013 9:28 am
by jjs
Thanks Tronic !
I will give that a try.