Saturday, April 26, 2008

Windows Maximum Path Length

I am currently running some grid jobs on my newly revamped Linux cluster running CentOS 5.1 64 bit. Somehow my customer's program generated files deep in a directory with at least 4 level. It created a lot of problem when I tried to copy to Windows via Filezilla. Those failed FTP transfer are having a path length longer than 256.

To avoid all these downstream activities in Windows, I 'move' all these files to there respective base directory and delete all these directories. In UNIX, you can achieve that with 'find'

find . -type f -exec mv {} . \;
find . -type d -depth rmdir {} \;

First find is to locate all the files (no directory) and execute a 'mv' to move the file to current directory. Second find is to locate all the directories, with the trick that we locate directory with depth first. With this, we are able to delete the deeper directory in the hierarchy. BTW, the second find will generate error 'cos the find also locate itself (".") and rmdir will try to remove it. It will fail 'cos you are not allow to remove itself or non-empty directory. Although it will not do any harm, you may want to avoid error by putting find in a loop and skip the current directory

for i in `find . -type d -depth`
do
    [ "$i" = "." ] || rmdir $i
done

Labels:

0 Comments:

Post a Comment

<< Home