FileUtils - Delete all but one file

I am trying to use FileUtils to delete Temporary Internet Files on
Windows using IE10, however on every pass it gives an permission denied
error on “Counters.dat”.

Is there any way I can use FileUtils to delete all but one file,
enabling all files to be deleted, but keep the counters.dat file?

It seems a known issue with IE10, but the file doesn’t show up in
Windows Explorer when “show hidden files” is ticked, and “hide
protected operating system files” is unticked.

Help please!

Subject: FileUtils - Delete all but one file
Date: gio 14 nov 13 10:44:32 +0100

Quoting Graeme H. ([email protected]):

Is there any way I can use FileUtils to delete all but one file,
enabling all files to be deleted, but keep the counters.dat file?

I have no idea whatsoever about how windows is handling directories,
but even without touching FileUtils, you can scan all entries of a
directory and decide whether to delete them according to the name of
the file.

For example, a function (not tested) could be as follows:

def delete_all_but_countersdat(path)
Dir::foreach(path) do |filename|
next if(filename==‘counters.dat’) # you could even use a regexp…
filepath=path+filename
next unless(File::file?(filepath)) # delete only if it is a file
STDERR.puts(“Removing #{filepath}”)
File::unlink(filepath)
end
end

Hope this helps

Carlo

I would do something like the following:

def remove_files
Dir["*/**"].each do |f|
should_skip = File.basename( f ) =~ /^Counters.dat$/
FileUtils.rm( f ) unless should_skip
end
end

Rescue the exception and continue if the filename matches ?