On Wed, Oct 20, 2010 at 1:54 AM, Simo M. [email protected] wrote:
- remove all junk*.cs files from dir
Thanks in advance.
Posted via http://www.ruby-forum.com/.
First select them using Dir (you can try to get fancy with a pattern
but I don’t think there is a way to specify multiple digits, so
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.
Then, use the grep method to select the ones you want, since we didn’t
the pattern above. You’ll have to give it a regexp, if you aren’t
with that, you can just use /\Afile\d+.cs\Z/ and change out the name
extension as necessary. It basically says if the string begins with
followed by one or more digits, followed by “.cs” and nothing else, then
is a match.
Then use each to iterate over the list of file names
And pass them to File.delete