On Friday 20 January 2012 at 1:02 PM, Alex Sweps wrote:
> Hello again everyone.
> This one should be a quick one for you. I am creating a directory
> structure and i want to name some of the folders with a variable but
> cannot figure out how. Any help would be great.
>
> Example: FileUtils.makedirs ('Backup\Test\Test2\@var\@var2@var3')
>
> Kind Regards
>
> --
> Posted via http://www.ruby-forum.com/.

Hi,

You can interpolate variables into strings using #{}, for example,

var1 = 'foo'
var2 = 'bar'
"Backup\Test\#{var1}\#{var2}" #=> "Backup\Test\foo\bar"

So one way of accomplishing what you want to do is to pass a string into Dir.mkdir[1], but you may also want to check out File.join[2] to see if it is more relevant to what you are trying to do.

Vikhyat Korrapati
http://vikhyat.net/

[1] http://ruby-doc.org/core-1.9.3/Dir.html#method-c-mkdir
[2] http://ruby-doc.org/core-1.9.3/File.html#method-c-join