On Jul 13, 2011, at 14:51 , Simon Harrison wrote:

> Thanks a lot. I didn't realise that FileUtils.mkdir accepted a format tring.

It doesn't. Philip's code is wrong.

> 10000 % ruby
> require 'fileutils'
> 
> (1..100).each do |num|
>  FileUtils.mkdir("prefix-%03d", num)
> end
> ^d
> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/fileutils.rb:1436:in `dup': can't dup Fixnum (TypeError)
> ...


What you really want to execute is:

> (1..100).each do |num|
>   FileUtils.mkdir "Prefix-%03d" % num
> end

which is just syntactic sugar for:

>   FileUtils.mkdir("Prefix-%03d".%(num))