First select them using Dir (you can try to get fancy with a pattern here,
but I don't think there is a way to specify multiple digits, so something
like junky.cs would get picked up by a "junk*.cs" and "junk[0-9].cs"
wouldn't pick up junk11.cs, so I'd just use "*" for the pattern. http://ruby-doc.org/core/classes/Dir.html#M002323
Then, use the grep method to select the ones you want, since we didn't use
the pattern above. You'll have to give it a regexp, if you aren't familiar
with that, you can just use /\Afile\d+\.cs\Z/ and change out the name and
extension as necessary. It basically says if the string begins with "file",
followed by one or more digits, followed by ".cs" and nothing else, then it
is a match. http://ruby-doc.org/core/classes/Enumerable.html#M003121
TRASH="#{ENV['HOME']}/.Trash" #might be specific to Mac OS X
Dir.glob("test/junk*.cs").each {|file| File.rename(file,
"#{TRASH}/#{File.basename(file)}")}
----------------------------
Dir.glob("test/junk*.cs").each {|file| FileUtils.rm_rf file}
----------------------------
--
« Le meilleur moyen de tenir sa parole est de ne jamais la donner. »
(Napoléon Bonaparte)
First select them using Dir (you can try to get fancy with a pattern here,
but I don't think there is a way to specify multiple digits, so something
like junky.cs would get picked up by a "junk*.cs" and "junk[0-9].cs"
wouldn't pick up junk11.cs, so I'd just use "*" for the pattern. class Dir - RDoc Documentation
Then, use the grep method to select the ones you want, since we didn't use
the pattern above. You'll have to give it a regexp, if you aren't familiar
with that, you can just use /\Afile\d+\.cs\Z/ and change out the name and
extension as necessary. It basically says if the string begins with "file",
followed by one or more digits, followed by ".cs" and nothing else, then it
is a match. module Enumerable - RDoc Documentation
Which star do you mean, the first one or the second one? I can't
really tell in my mail reader since Google Mail at some point dropped
the "show in fixed width font" option.
First one:
That's the splash operator which in this case unrolls an array
argument to multiple method arguments.
Second one:
Ruby's documentation is bad in places - but not that bad. Try
ri19 'Dir.'
ri19 'Dir.glob'
Cheers
robert
···
2010/10/20 Une Bévue <unbewusst.sein@fai.invalid>: