2007/7/12, Ronald Fischer <ronald.fischer / venyon.com>:
> (Ruby 1.8.6 under Windows)
>
> My application creates a series of temporary files. I decided to use
> the tempfile module of Ruby, but I needed to control the file extension
> of the generated temporary file (should end in .xml). I came up with
> the following solution:
>
>     file=Tempfile.new('.tempreq','/thome/requests')
>     file << '....' # populate the file
>     path=file.path # remember the generated filename
>     file.close
>     result=path+'.xml' # add desired extension to the filename
>     File.rename(path,result) # rename file
>     at_exit { File::delete(result) } # remove file at exit
>
> When the exit handler jumps into action, I get however the following
> error:
>
> H:\thome\grubylib/TfwCommon.rb:433:in `delete': Permission denied -
> /thome/requests/.tempr
> eq.3176.0.xml (Errno::EACCES)
>
> After the program has ended, I can however erase the file from the
> command line with
> no problems. Why do I get a "permission denied" here? Is there a better
> way to
> achieve my goal?

I'd just use the block form:

ruby -r tempfile -e 'Tempfile.open("foo", ".") {|io| io.puts 123}'

After that there is no file prefixed "foo" in ".".

Kind regards

robert