Saturday, February 8, 2014

Infinite folders!

Hit a bug that cost me a full evening.  O_O

I wrote a simple script to copy a directory into another*.  I didn't check for one fatal condition... I didn't check if the destination directory is a child of the source directory. So after about 10 seconds of running this script, I now had thousands and thousands of folders nested one after another.  I then tried to delete them, but got the error, "The source file names are larger than is supported by the file system."  Searching for this problem online gave me several possible solutions which none of them worked.  Most involved using robocopy to purge a directory, but in windows robocopy would just crash, and from an emergency boot disk it would run for an hour and end up doing nothing.  Other solutions involved manual steps that may have worked eventually, but I had so many folders here it might have taken me a hundred years.

*I know I know, I should have just used Apache commons FileUtils library, but I figured it is like a 20 line script, easier to write it than to pull in a new library for the one thing I needed.

What ended up working was creating a windows batch file to rename a child directory, move it up a level, then delete the first directory, repeat.

My infinitely nested folder was named "assets".
I cut and paste that folder to C: and ran this script:

@echo off
:LoopStart
REN "assets/assets" "temp"
MOVE "assets/temp" "C:/"
RMDIR "assets"
REN "temp" "assets"
GOTO LoopStart
:LoopEnd

Please don't take this as an opportunity to post comments about how much better Mac is than Windows. I don't care, thanks! :-)

No comments:

Post a Comment