How to use the safe_unlink method?

Guy-

Thanks, but a follow-up question:

How exactly would I rewrite my file (which happens to be named “dl.rb”) which currently includes just this text:

require ‘ftools’
File.safe_unlink(“.\output*.*”)

Do you think this code should be correct as written? (I don’t understand your “ruby -rftools -e” text.)

NOTE: In case it makes a difference, I’m using ruby on an NT machine.

Thanks!

-Kurt

···

-----Original Message-----
From: ts [mailto:decoux@moulon.inra.fr]
Sent: Wednesday, August 14, 2002 12:59 AM
To: ruby-talk@ruby-lang.org
Cc: ruby-talk@ruby-lang.org
Subject: Re: How to use the safe_unlink method?

File.safe_unlink(“.\output*.*”)

Well, it work fine

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

pigeon% ruby -rftools -e ‘File.safe_unlink(“.\output*.*”)’
pigeon%

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

safe_unlink don’t accept meta-characters like *

Guy Decoux

He’s creating a file named “.output*.*” and deleting it with the line
you used. He’s showing you 2 errors there:

  1. usage of '' in the string: it’s gotta be escaped: “\”
    NOTE: maybe Ruby uses ‘/’ as a dir. separator even in Win*, you’ll
    have to test
  2. File.safe_unlink doesn’t accept file globs.

Use something like (untested)

require ‘ftools’
files = Dir[“.\output\.”]
files.each { |x| File.safe_unlink x }

···

On Thu, Aug 15, 2002 at 03:01:41AM +0900, Kurt Euler wrote:

Guy-

Thanks, but a follow-up question:

How exactly would I rewrite my file (which happens to be named “dl.rb”) which currently includes just this text:

require ‘ftools’
File.safe_unlink(“.\output*.*”)

Do you think this code should be correct as written? (I don’t
understand your “ruby -rftools -e” text.)


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

  • JHM wonders what Joey did to earn “I’d just like to say, for the record,
    that Joey rules.”
    – Seen on #Debian