Removing files with varied capitalization

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.
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.
  • bfabry

    Because I wanted to know what one was, a bash way to do this:

    $ls -1 | grep -i rakefile | xargs rm

    • http://ekenosen.net/nick nevans

      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. ;-)

      • http://avdi.org avdi

        I demand a Korn shell version.

  • http://ekenosen.net/nick nevans

    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. ;-)

  • http://wideteams.com Avdi Grimm

    I demand a Korn shell version.