Archive

Archive for March, 2007

More on spaces: mass delete of superfluous folders in a tree

March 6th, 2007 Josh Graham No comments

I still hate the handling of spaces – especially when you’re throwing in mixed path delimiters using nice GNU tools on DOS/NTFS.

If you ever want to get rid of SVN or CVS folders (or whatever) in a large source tree after someone has zipped it and sent it to you straight from their workspace, and Explorer’s Search window barfs with that many matching folders all over the place, then try this:

  1. Get unxutils
  2. Use the zsh included
  3. Realise zsh has bipolar tendancies when dealing with “DOS backslash to delimit directories in paths” and “UNIX slash to delimit directories in paths” and “UNIX backslash to quote special characters”
  4. Put unxutil’s usr/local/wbin at the front of your PATH (to get the GNU find, not the DOS one)
  5. Unfortunately -exec ls {} \; doesn’t do the trick because ls can’t handle the spaces and/or backslashes and -exec ls “{}” \; doesn’t have any affect
  6. Use the following neat trick (after 30 mins of mucking around with the bipolar tendancies)

  7. find . -name 'CVS' -print | tr '\\' '/' | while read filename
    do
    rm -r "$filename"
    done

  8. The little translate sorts out GNU find -print returning paths with backslashes and the while loop allows you to do lots of things, including removing the directory :-)

It’s slower than -exec or xargs but it works.

Categories: Coding, Operating Systems, Rant Tags: