title: Delete Files That Are Too Long Using Bash
body: <p>This is not a duplicate as I want to achieve the result without using Windows tools as mentioned in this post <a href="https://superuser.com/questions/78434/tool-for-deleting-directories-with-path-names-too-long-for-normal-delete">https://superuser.com/questions/78434/tool-for-deleting-directories-with-path-names-too-long-for-normal-delete</a></p>
  
  <p>I am deleting SVN ignored files that Maven has created (something like this)</p>
  
  <pre><code>jaxb/com.mycompany.test.jaxb.upload-document/target
  jaxb/com.mycompany.test.jaxb.fpml/target
  jaxb/com.mycompany.test.jaxb.fixml/target
  jaxb/com.mycompany.test.jaxb.trade-header/target
  jaxb/com.mycompany.test.jaxb.schema-versioning/target
  test-risk/target
  </code></pre>
  
  <p>I am using the following command but it fails when the path is too long on Windows.</p>
  
  <pre><code>echo "Deleting ignored files"
  svn stat --no-ignore | awk '$1=="I" { print $0 }'|awk '{$1=""; print $0}'|tr '\\' '/'|while read file;do rm -rf "$file" ;done;
  </code></pre>
  
  <p>This is run as part of a script that runs on Unix as well as Windows which is why I can't use any of the previously mentioned tools.</p>
  
  <p>What I need to do is write a routine that checks to see if there are any errors due to long file length and recursively rename the directories from the top down to the bottom with single characters in an attempt to shorten the path.</p>
  
  <p>I'm not sure how to check for the errors ("Directory not empty" and " File or path name too long").</p>
  
  <p>Ideally I'd like to fail the "rm -rf" immediately rather than throwing the error hundreds of times.</p>
  
  <p>Finally, I'm not sure what the most efficient way to recursively rename the directories is.</p>
  
  <p>EDIT: If I just assume that all directories are going to cause the issue I could get the roots cd to them in turn and recursively rename the sub-dirs. This way I don't have to worry about catching errors from rm.</p>