From: Robert Klemme Date: 2010-10-07T16:15:44+09:00 Subject: Re: how do i close a file that is open in ruby On Thu, Oct 7, 2010 at 8:59 AM, Amit Tomar wrote: > Hi all, >         i would like to close a file that is open in particular > directory .this is my code > > require 'fileutils' > >    dir ="C:/Documents and Settings/x0138466/Local Settings/Temp" >    Dir.chdir(dir) >    Dir["*"].each do |f| >    f.close f is a String! You cannot close a String. >        #  File.close > >      FileUtils.rm_rf(f) >     #FileUtils.rm(f) > >  end >    Some of the file in TEMP folder is open or you can say used by some > process but i want to close but with above code am not ablr to do > that??is it possible to achive from above code?? From your recent postings I conclude that you mean "opened by another process". No, you cannot close a file from another process without going through major operating system specific tricks (on Windows there is ProcessExplorer of former Sysinternals for example). You also usually need specific privileges, i.e. have root rights on a *nix system and have administrative permissions on a Windows box. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/