How to use the safe_unlink method?


I’m trying to write a progam that will delete all files in a directory.

Here’s a test program using safe_unlink with which I’m trying to delete all files in the immediate subdirectory (output) to the program:

require 'ftools’

When I run this program, nothing happens, not even an error. No files are delete anywhere.

In an earlier question about deleting files, a couple of you wrote a several-line procedure without mentioning the safe_unlink method. I since read a bit about this method, so I thought I’d ask about it directly.

Thanks a bunch!


Well, it work fine

pigeon% ls -d .*
./ ../ .output*.*

pigeon% ruby -rftools -e 'File.safe_unlink(".\output\*.*")'

pigeon% ls -d .*
./ ../

safe_unlink don't accept meta-characters like *

Guy Decoux