Working Remotely? Thinking about it?

Are you a member of a geographically dispersed team? Are you thinking of working remotely, or hiring remote developers? Wide Teams is my new blog and podcast for distributed teams. Check it out for getting started guides, tips and best practices, news, interviews, screencasts, and more all about working remotely and collaborating with wide-spread teams.

Removing files with varied capitalization

2010 March 3
tags: ,
by avdi

Nothing ground-breaking today, just a one-liner that I expected to be longer than a one-liner.

# Remove Rakefile, rakefile, RakeFile, etc...
File.delete(*Dir.glob('rakefile', File::FNM_CASEFOLD))

There are two notable things going on here:

  1. Dir.glob can take optional bitflags; in this case, FNM_CASEFOLD means to ignore case.
  2. File.delete can take N arguments.
Bookmark and Share
Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.

Related posts:

  1. Double-Load Guards in Ruby
  2. Smart Requires in Ruby
  • bfabry
    Because I wanted to know what one was, a bash way to do this:

    $ls -1 | grep -i rakefile | xargs rm
  • the bash and safe-find way to do this:

    find . -maxdepth 1 -iname 'rakefile' -print0 | xargs -0 rm

    This has the benefits of being four characters longer than Avdi's ruby version, harder for newbies to understand, and outside of our favorite programming language. ;-)
  • I demand a Korn shell version.
blog comments powered by Disqus